@@ -11,6 +11,7 @@ import (
1111 "github.com/gin-gonic/gin"
1212 "github.com/google/uuid"
1313 "github.com/shopspring/decimal"
14+ "golang.org/x/exp/slices"
1415 "gorm.io/gorm"
1516)
1617
@@ -34,7 +35,7 @@ type TransactionLinks struct {
3435type TransactionQueryFilter struct {
3536 Date time.Time `form:"date"`
3637 Amount decimal.Decimal `form:"amount"`
37- Note string `form:"note"`
38+ Note string `form:"note" filterField:"false" `
3839 BudgetID string `form:"budget"`
3940 SourceAccountID string `form:"source"`
4041 DestinationAccountID string `form:"destination"`
@@ -73,7 +74,6 @@ func (f TransactionQueryFilter) ToCreate(c *gin.Context) (models.TransactionCrea
7374 return models.TransactionCreate {
7475 Date : f .Date ,
7576 Amount : f .Amount ,
76- Note : f .Note ,
7777 BudgetID : budgetID ,
7878 SourceAccountID : sourceAccountID ,
7979 DestinationAccountID : destinationAccountID ,
@@ -224,7 +224,7 @@ func (co Controller) GetTransactions(c *gin.Context) {
224224 }
225225
226226 // Get the fields set in the filter
227- queryFields , _ := httputil .GetURLFields (c .Request .URL , filter )
227+ queryFields , setFields := httputil .GetURLFields (c .Request .URL , filter )
228228
229229 // Convert the QueryFilter to a Create struct
230230 create , ok := filter .ToCreate (c )
@@ -254,6 +254,12 @@ func (co Controller) GetTransactions(c *gin.Context) {
254254 })
255255 }
256256
257+ if filter .Note != "" {
258+ query = query .Where ("note LIKE ?" , fmt .Sprintf ("%%%s%%" , filter .Note ))
259+ } else if slices .Contains (setFields , "Note" ) {
260+ query = query .Where ("note = ''" )
261+ }
262+
257263 var transactions []models.Transaction
258264 if ! queryWithRetry (c , query .Find (& transactions )) {
259265 return
0 commit comments