Skip to content

Commit

Permalink
Merge pull request #34 from Oakes6/features/get-variations
Browse files Browse the repository at this point in the history
add getvariations paging params
  • Loading branch information
spiegel-im-spiegel authored Feb 8, 2024
2 parents 209d815 + ddfced0 commit 3db3b21
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions query/getvariations.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ var requestsOfGetVariations = []RequestFilter{
OfferCount,
PartnerTag,
PartnerType,
VariationCount,
VariationPage,
}

// RequestFilters adds RequestFilter to Query instance
Expand Down
5 changes: 5 additions & 0 deletions query/getvariations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func TestRequestFiltersInGetVariations(t *testing.T) {
{q: NewGetVariations("", "", "").Request(SearchIndex, "All"), str: `{"Operation":"GetVariations"}`},
{q: NewGetVariations("", "", "").Request(SortBy, "AvgCustomerReviews"), str: `{"Operation":"GetVariations"}`},
{q: NewGetVariations("", "", "").Request(Title, "foo"), str: `{"Operation":"GetVariations"}`},
{q: NewGetVariations("", "", "").Request(VariationCount, 5), str: `{"Operation":"GetVariations","VariationCount":5}`},
{q: NewGetVariations("", "", "").Request(VariationCount, 11), str: `{"Operation":"GetVariations"}`},
{q: NewGetVariations("", "", "").Request(VariationCount, -1), str: `{"Operation":"GetVariations"}`},
{q: NewGetVariations("", "", "").Request(VariationPage, 2), str: `{"Operation":"GetVariations","VariationPage":2}`},
{q: NewGetVariations("", "", "").Request(VariationPage, 0), str: `{"Operation":"GetVariations"}`},
}

for _, tc := range testCases {
Expand Down
13 changes: 13 additions & 0 deletions query/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const (
SearchIndex
SortBy
Title
VariationCount
VariationPage
)

func (f RequestFilter) findIn(list []RequestFilter) bool {
Expand Down Expand Up @@ -115,6 +117,8 @@ type request struct {
SearchIndex string `json:",omitempty"`
SortBy string `json:",omitempty"`
Title string `json:",omitempty"`
VariationCount int `json:",omitempty"`
VariationPage int `json:",omitempty"`
}

// mapFilter is a helper function for (*filters).WithFilters
Expand Down Expand Up @@ -282,7 +286,16 @@ func (r *request) mapFilter(filter RequestFilter, filterValue interface{}) {
if param, ok := filterValue.(string); ok && filter.isVlidString(param) {
r.Title = param
}
case VariationCount:
if count, ok := filterValue.(int); ok && 0 < count && count < 11 {
r.VariationCount = count
}
case VariationPage:
if count, ok := filterValue.(int); ok && 0 < count {
r.VariationPage = count
}
}

}

/* Copyright 2019-2022 Spiegel and contributors
Expand Down

0 comments on commit 3db3b21

Please sign in to comment.