From 2d4becd2ee0ca85de517c2d054990718ef73cd54 Mon Sep 17 00:00:00 2001 From: "taekyu.kang" Date: Wed, 6 Mar 2024 14:18:51 +0900 Subject: [PATCH] feature. support filter array --- internal/pagination/pagination.go | 51 ++++++++++++++++--------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/internal/pagination/pagination.go b/internal/pagination/pagination.go index 0b2295f0..22e4ad47 100644 --- a/internal/pagination/pagination.go +++ b/internal/pagination/pagination.go @@ -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, + }) + + } } } }