Skip to content

Commit e54d9de

Browse files
committed
fix: incorrect join with specific combination of filters
1 parent fe2e3a5 commit e54d9de

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

internal/storage/ledger/resource.go

+13-7
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,27 @@ type filter struct {
6262

6363
type repositoryHandlerBuildContext[Opts any] struct {
6464
ledgercontroller.ResourceQuery[Opts]
65-
filters map[string]any
65+
filters map[string][]any
6666
}
6767

6868
func (ctx repositoryHandlerBuildContext[Opts]) useFilter(v string, matchers ...func(value any) bool) bool {
6969
value, ok := ctx.filters[v]
7070
if !ok {
7171
return false
7272
}
73+
if len(matchers) == 0 {
74+
return true
75+
}
76+
7377
for _, matcher := range matchers {
74-
if !matcher(value) {
75-
return false
78+
for _, v := range value {
79+
if matcher(v) {
80+
return true
81+
}
7682
}
7783
}
7884

79-
return true
85+
return false
8086
}
8187

8288
type repositoryHandler[Opts any] interface {
@@ -93,12 +99,12 @@ type resourceRepository[ResourceType, OptionsType any] struct {
9399
ledger ledger.Ledger
94100
}
95101

96-
func (r *resourceRepository[ResourceType, OptionsType]) validateFilters(builder query.Builder) (map[string]any, error) {
102+
func (r *resourceRepository[ResourceType, OptionsType]) validateFilters(builder query.Builder) (map[string][]any, error) {
97103
if builder == nil {
98104
return nil, nil
99105
}
100106

101-
ret := make(map[string]any)
107+
ret := make(map[string][]any)
102108
properties := r.resourceHandler.filters()
103109
if err := builder.Walk(func(operator string, key string, value any) (err error) {
104110

@@ -129,7 +135,7 @@ func (r *resourceRepository[ResourceType, OptionsType]) validateFilters(builder
129135
return err
130136
}
131137
}
132-
ret[property.name] = value
138+
ret[property.name] = append(ret[property.name], value)
133139
break
134140
}
135141

test/e2e/api_volumes_test.go

+30-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ var _ = Context("Ledger accounts list API tests", func() {
139139
})
140140
})
141141

142-
When("Get Volumes and Balances Filter by address account", func() {
142+
When("Get volumes and balances filter by partial address account", func() {
143143
It("should be ok", func() {
144144
response, err := GetVolumesWithBalances(
145145
ctx,
@@ -167,6 +167,35 @@ var _ = Context("Ledger accounts list API tests", func() {
167167
})
168168
})
169169

170+
When("Get volumes and balances filter by partial account address and full address", func() {
171+
It("should be ok", func() {
172+
response, err := GetVolumesWithBalances(
173+
ctx,
174+
testServer.GetValue(),
175+
operations.V2GetVolumesWithBalancesRequest{
176+
InsertionDate: pointer.For(true),
177+
RequestBody: map[string]interface{}{
178+
"$or": []map[string]any{
179+
{
180+
"$match": map[string]any{
181+
"account": "account:",
182+
},
183+
},
184+
{
185+
"$match": map[string]any{
186+
"account": "world",
187+
},
188+
},
189+
},
190+
},
191+
Ledger: "default",
192+
},
193+
)
194+
Expect(err).ToNot(HaveOccurred())
195+
Expect(response.Data).To(HaveLen(3))
196+
})
197+
})
198+
170199
When("Get Volumes and Balances Filter by address account a,d and end-time now effective", func() {
171200
It("should be ok", func() {
172201
response, err := GetVolumesWithBalances(

0 commit comments

Comments
 (0)