From 357b27b3648263f6338c233037f9032ff93970e9 Mon Sep 17 00:00:00 2001 From: "taekyu.kang" Date: Mon, 19 Feb 2024 10:37:44 +0900 Subject: [PATCH] feature. support for ilter --- internal/filter/util.go | 4 ---- internal/pagination/pagination.go | 14 ++++++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/internal/filter/util.go b/internal/filter/util.go index 68b9bcc4..44f350f7 100644 --- a/internal/filter/util.go +++ b/internal/filter/util.go @@ -5,7 +5,6 @@ import ( "strings" "time" - "github.com/openinfradev/tks-api/pkg/log" "gorm.io/gorm/schema" "goyave.dev/goyave/v4/util/sliceutil" ) @@ -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 diff --git a/internal/pagination/pagination.go b/internal/pagination/pagination.go index 73b58c9f..d7547d70 100644 --- a/internal/pagination/pagination.go +++ b/internal/pagination/pagination.go @@ -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" @@ -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 @@ -41,6 +41,7 @@ type Pagination struct { } type Filter struct { + Or bool Relation string Column string Operator string @@ -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) @@ -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] @@ -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, }) } }