Skip to content

Commit

Permalink
Merge pull request #265 from openinfradev/combined_filter
Browse files Browse the repository at this point in the history
feature. support filter array
  • Loading branch information
cho4036 authored Mar 6, 2024
2 parents c6055e9 + 2d4becd commit eeca31a
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions internal/pagination/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,34 +192,37 @@ func NewPagination(urlParams *url.Values) *Pagination {
for _, filterValue := range value {
arr := strings.Split(filterValue, "|")

column := arr[0]
releation := ""
arrColumns := strings.Split(column, ".")
if len(arrColumns) > 1 {
releation = arrColumns[0]
column = arrColumns[1]
}
columns := strings.Split(arr[0], ",")
for i, column := range columns {
releation := ""
arrColumns := strings.Split(column, ".")
if len(arrColumns) > 1 {
releation = arrColumns[0]
column = arrColumns[1]
}

trimmedStr := strings.Trim(arr[1], "[]")
values := strings.Split(trimmedStr, ",")
trimmedStr := strings.Trim(arr[1], "[]")
values := strings.Split(trimmedStr, ",")

op := "$cont"
if len(arr) == 3 {
op = arr[2]
}
op := "$cont"
if len(arr) == 3 {
op = arr[2]
}

or := false
if key == OR || key == OR_ARRAY {
or = true
}
or := false
if i > 0 || key == OR || key == OR_ARRAY {
or = true
}

pg.Filters = append(pg.Filters, Filter{
Column: helper.ToSnakeCase(strings.Replace(column, "[]", "", -1)),
Relation: releation,
Operator: op,
Values: values,
Or: or,
})
pg.Filters = append(pg.Filters, Filter{
Column: helper.ToSnakeCase(strings.Replace(column, "[]", "", -1)),
Relation: releation,
Operator: op,
Values: values,
Or: or,
})

}
}
}
}
Expand Down

0 comments on commit eeca31a

Please sign in to comment.