Skip to content

Commit cabd218

Browse files
fix(SPV-000): enhance DefaultsIfNil to check for empty QueryParams (#816)
1 parent c9fe3f6 commit cabd218

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

actions/admin/contact_old.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func contactsSearchOld(c *gin.Context, _ *reqctx.AdminContext) {
4141
return
4242
}
4343

44-
reqParams.DefaultsIfNil()
44+
reqParams.DefaultsIfNilOrEmpty()
4545

4646
contacts, err := engine.GetContacts(
4747
c.Request.Context(),

actions/contacts/search.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func search(c *gin.Context, userContext *reqctx.UserContext) {
4343
return
4444
}
4545

46-
reqParams.DefaultsIfNil()
46+
reqParams.DefaultsIfNilOrEmpty()
4747

4848
contacts, err := engine.GetContactsByXpubID(
4949
c.Request.Context(),
@@ -197,7 +197,7 @@ func searchContacts(c *gin.Context, reqXPubID string, paymail string) ([]*engine
197197
return nil, 0
198198
}
199199

200-
reqParams.DefaultsIfNil()
200+
reqParams.DefaultsIfNilOrEmpty()
201201

202202
contacts, err := engine.GetContactsByXpubID(
203203
c.Request.Context(),

models/filter/generics.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ type SearchModel[TFilter any] struct {
1616
QueryParams *QueryParams `json:"params,omitempty" swaggertype:"object,string" example:"page:1,page_size:10,order_by_field:created_at,order_by_direction:desc"`
1717
}
1818

19-
// DefaultsIfNil fills empty but necessary fields with default values
20-
func (sm *SearchModel[TFilter]) DefaultsIfNil() {
21-
if sm.QueryParams == nil {
19+
// DefaultsIfNilOrEmpty fills empty but necessary fields with default values
20+
func (sm *SearchModel[TFilter]) DefaultsIfNilOrEmpty() {
21+
if sm.QueryParams == nil || sm.QueryParams.isEmpty() {
2222
sm.QueryParams = DefaultQueryParams()
2323
}
2424
}
25+
26+
func (qp QueryParams) isEmpty() bool {
27+
return qp == (QueryParams{})
28+
}

0 commit comments

Comments
 (0)