Skip to content

Commit

Permalink
feature. support for ilter
Browse files Browse the repository at this point in the history
  • Loading branch information
ktkfree committed Feb 20, 2024
1 parent 3cbaf4b commit 357b27b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 0 additions & 4 deletions internal/filter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strings"
"time"

"github.com/openinfradev/tks-api/pkg/log"
"gorm.io/gorm/schema"
"goyave.dev/goyave/v4/util/sliceutil"
)
Expand Down Expand Up @@ -156,9 +155,6 @@ func getDataType(field *schema.Field) DataType {
}

func ConvertToSafeType(arg string, dataType DataType) (interface{}, bool) {
log.Info(arg)
log.Info(dataType)

switch dataType {
case DataTypeText, DataTypeTextArray, DataTypeEnum, DataTypeEnumArray:
return arg, true
Expand Down
14 changes: 10 additions & 4 deletions internal/pagination/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/openinfradev/tks-api/internal/helper"
"github.com/openinfradev/tks-api/internal/serializer"
"github.com/openinfradev/tks-api/pkg/domain"
"github.com/openinfradev/tks-api/pkg/log"
"gorm.io/gorm"

"goyave.dev/goyave/v4"
Expand All @@ -22,6 +21,7 @@ const SORT_ORDER = "sortOrder"
const PAGE_NUMBER = "pageNumber"
const PAGE_SIZE = "pageSize"
const FILTER = "filter"
const OR = "or"
const COMBINED_FILTER = "combinedFilter"

var DEFAULT_LIMIT = 10
Expand All @@ -41,6 +41,7 @@ type Pagination struct {
}

type Filter struct {
Or bool
Relation string
Column string
Operator string
Expand Down Expand Up @@ -100,7 +101,7 @@ func (p *Pagination) MakePaginationRequest() {
Field: field,
Operator: convertOperator(f.Operator),
Args: f.Values,
Or: false,
Or: f.Or,
}

pgFilters = append(pgFilters, &pgFilter)
Expand Down Expand Up @@ -187,9 +188,8 @@ func NewPagination(urlParams *url.Values) (*Pagination, error) {
return nil, fmt.Errorf("Invalid query string : combinedFilter ")
}
}
case FILTER:
case FILTER, OR:
for _, filterValue := range value {
log.Debug("filterValue : ", filterValue)
arr := strings.Split(filterValue, "|")

column := arr[0]
Expand All @@ -208,11 +208,17 @@ func NewPagination(urlParams *url.Values) (*Pagination, error) {
op = arr[2]
}

or := false
if key == OR {
or = true
}

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 357b27b

Please sign in to comment.