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