Add date filtering to backend
This commit is contained in:
parent
a031dd5bb1
commit
f8a8a6fc0c
@ -69,4 +69,5 @@ FROM display_transactions AS transactions
|
||||
WHERE (NOT @filter_category::boolean OR transactions.category_id = @category_id)
|
||||
AND (NOT @filter_account::boolean OR transactions.account_id = @account_id)
|
||||
AND (NOT @filter_payee::boolean OR transactions.payee_id = @payee_id)
|
||||
AND transactions.date BETWEEN @from_date AND @to_date
|
||||
AND transactions.budget_id = @budget_id;
|
@ -123,7 +123,8 @@ FROM display_transactions AS transactions
|
||||
WHERE (NOT $1::boolean OR transactions.category_id = $2)
|
||||
AND (NOT $3::boolean OR transactions.account_id = $4)
|
||||
AND (NOT $5::boolean OR transactions.payee_id = $6)
|
||||
AND transactions.budget_id = $7
|
||||
AND transactions.date BETWEEN $7 AND $8
|
||||
AND transactions.budget_id = $9
|
||||
`
|
||||
|
||||
type GetFilteredTransactionsParams struct {
|
||||
@ -133,6 +134,8 @@ type GetFilteredTransactionsParams struct {
|
||||
AccountID uuid.UUID
|
||||
FilterPayee bool
|
||||
PayeeID uuid.NullUUID
|
||||
FromDate time.Time
|
||||
ToDate time.Time
|
||||
BudgetID uuid.UUID
|
||||
}
|
||||
|
||||
@ -144,6 +147,8 @@ func (q *Queries) GetFilteredTransactions(ctx context.Context, arg GetFilteredTr
|
||||
arg.AccountID,
|
||||
arg.FilterPayee,
|
||||
arg.PayeeID,
|
||||
arg.FromDate,
|
||||
arg.ToDate,
|
||||
arg.BudgetID,
|
||||
)
|
||||
if err != nil {
|
||||
|
@ -1,7 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"git.javil.eu/jacob1123/budgeteer/postgres"
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -9,9 +11,11 @@ import (
|
||||
)
|
||||
|
||||
type FilterTransactionsRequest struct {
|
||||
CategoryID string `json:"category_id"`
|
||||
PayeeID string `json:"payee_id"`
|
||||
AccountID string `json:"account_id"`
|
||||
CategoryID string `json:"category_id"`
|
||||
PayeeID string `json:"payee_id"`
|
||||
AccountID string `json:"account_id"`
|
||||
FromDate time.Time `json:"from_date"`
|
||||
ToDate time.Time `json:"to_date"`
|
||||
}
|
||||
|
||||
func (h *Handler) filteredTransactions(c *gin.Context) {
|
||||
@ -31,6 +35,8 @@ func (h *Handler) filteredTransactions(c *gin.Context) {
|
||||
|
||||
params := postgres.GetFilteredTransactionsParams{
|
||||
BudgetID: budgetUUID,
|
||||
FromDate: request.FromDate,
|
||||
ToDate: request.ToDate,
|
||||
}
|
||||
params.CategoryID, params.FilterCategory = parseEmptyUUID(request.CategoryID)
|
||||
accountID, filterAccount := parseEmptyUUID(request.AccountID)
|
||||
|
Loading…
x
Reference in New Issue
Block a user