forked from ebhomengo/niki
Merge pull request 'feat(admin): Add status filter in get all refer times(#193)' (#194) from stage/hamed/add-refer-time-filter into develop
Reviewed-on: ebhomengo/niki#194
This commit is contained in:
commit
3ac97bce91
|
|
@ -5,6 +5,7 @@ import (
|
||||||
|
|
||||||
refertimeparam "git.gocasts.ir/ebhomengo/niki/param/admin/refer_time"
|
refertimeparam "git.gocasts.ir/ebhomengo/niki/param/admin/refer_time"
|
||||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||||
|
queryparam "git.gocasts.ir/ebhomengo/niki/pkg/query_param"
|
||||||
echo "github.com/labstack/echo/v4"
|
echo "github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -13,6 +14,7 @@ import (
|
||||||
// @Tags Admins ReferTimes
|
// @Tags Admins ReferTimes
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
|
// @Param filter_status query entity.ReferTimeStatus false "Filter by KindBoxReq status" Format(enum)
|
||||||
// @Success 200 {object} adminrefertimeparam.GetAllReferTimeResponse
|
// @Success 200 {object} adminrefertimeparam.GetAllReferTimeResponse
|
||||||
// @Failure 400 {string} "Bad request"
|
// @Failure 400 {string} "Bad request"
|
||||||
// @Security AuthBearerAdmin
|
// @Security AuthBearerAdmin
|
||||||
|
|
@ -20,12 +22,24 @@ import (
|
||||||
func (h Handler) GetAll(c echo.Context) error {
|
func (h Handler) GetAll(c echo.Context) error {
|
||||||
var req refertimeparam.GetAllReferTimeRequest
|
var req refertimeparam.GetAllReferTimeRequest
|
||||||
|
|
||||||
listCities, err := h.adminReferTimeSvc.GetAll(c.Request().Context(), req)
|
if err := c.Bind(&req); err != nil {
|
||||||
|
return echo.NewHTTPError(http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Filter = queryparam.GetFilterParams(c)
|
||||||
|
|
||||||
|
resp, err := h.adminReferTimeSvc.GetAll(c.Request().Context(), req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg, code := httpmsg.Error(err)
|
msg, code := httpmsg.Error(err)
|
||||||
|
if resp.FieldErrors != nil {
|
||||||
|
return c.JSON(code, httpmsg.ErrorResponse{
|
||||||
|
Message: msg,
|
||||||
|
Errors: resp.FieldErrors,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return echo.NewHTTPError(code, msg)
|
return echo.NewHTTPError(code, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, listCities)
|
return c.JSON(http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
19
docs/docs.go
19
docs/docs.go
|
|
@ -1166,6 +1166,19 @@ const docTemplate = `{
|
||||||
"Admins ReferTimes"
|
"Admins ReferTimes"
|
||||||
],
|
],
|
||||||
"summary": "Get all refer times",
|
"summary": "Get all refer times",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"enum": [
|
||||||
|
"active",
|
||||||
|
"inactive"
|
||||||
|
],
|
||||||
|
"type": "string",
|
||||||
|
"format": "enum",
|
||||||
|
"description": "Filter by KindBoxReq status",
|
||||||
|
"name": "filter_status",
|
||||||
|
"in": "query"
|
||||||
|
}
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "OK",
|
||||||
|
|
@ -3420,6 +3433,12 @@ const docTemplate = `{
|
||||||
"items": {
|
"items": {
|
||||||
"$ref": "#/definitions/entity.ReferTime"
|
"$ref": "#/definitions/entity.ReferTime"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"field_errors": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1155,6 +1155,19 @@
|
||||||
"Admins ReferTimes"
|
"Admins ReferTimes"
|
||||||
],
|
],
|
||||||
"summary": "Get all refer times",
|
"summary": "Get all refer times",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"enum": [
|
||||||
|
"active",
|
||||||
|
"inactive"
|
||||||
|
],
|
||||||
|
"type": "string",
|
||||||
|
"format": "enum",
|
||||||
|
"description": "Filter by KindBoxReq status",
|
||||||
|
"name": "filter_status",
|
||||||
|
"in": "query"
|
||||||
|
}
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "OK",
|
||||||
|
|
@ -3409,6 +3422,12 @@
|
||||||
"items": {
|
"items": {
|
||||||
"$ref": "#/definitions/entity.ReferTime"
|
"$ref": "#/definitions/entity.ReferTime"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"field_errors": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -402,6 +402,10 @@ definitions:
|
||||||
items:
|
items:
|
||||||
$ref: '#/definitions/entity.ReferTime'
|
$ref: '#/definitions/entity.ReferTime'
|
||||||
type: array
|
type: array
|
||||||
|
field_errors:
|
||||||
|
additionalProperties:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
type: object
|
type: object
|
||||||
adminserviceparam.Data:
|
adminserviceparam.Data:
|
||||||
properties:
|
properties:
|
||||||
|
|
@ -1789,6 +1793,15 @@ paths:
|
||||||
get:
|
get:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- description: Filter by KindBoxReq status
|
||||||
|
enum:
|
||||||
|
- active
|
||||||
|
- inactive
|
||||||
|
format: enum
|
||||||
|
in: query
|
||||||
|
name: filter_status
|
||||||
|
type: string
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,15 @@
|
||||||
package adminrefertimeparam
|
package adminrefertimeparam
|
||||||
|
|
||||||
import "git.gocasts.ir/ebhomengo/niki/entity"
|
import (
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/param"
|
||||||
|
)
|
||||||
|
|
||||||
type GetAllReferTimeRequest struct{}
|
type GetAllReferTimeRequest struct {
|
||||||
|
Filter param.FilterRequest
|
||||||
|
}
|
||||||
|
|
||||||
type GetAllReferTimeResponse struct {
|
type GetAllReferTimeResponse struct {
|
||||||
Data []entity.ReferTime `json:"data"`
|
Data []entity.ReferTime `json:"data"`
|
||||||
|
FieldErrors map[string]string `json:"field_errors,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,18 +9,18 @@ import (
|
||||||
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
|
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d *DB) GetAll(ctx context.Context) ([]entity.ReferTime, error) {
|
func (d *DB) GetAll(ctx context.Context, status entity.ReferTimeStatus) ([]entity.ReferTime, error) {
|
||||||
const op = "mysqlrefertime.GetAll"
|
const op = "mysqlrefertime.GetAll"
|
||||||
|
|
||||||
query := `SELECT * FROM refer_times where status = 'active';`
|
query := `SELECT * FROM refer_times where status = ?;`
|
||||||
//nolint
|
|
||||||
stmt, err := d.conn.PrepareStatement(ctx, mysql.StatementKeyReferTimeGetAll, query)
|
stmt, err := d.conn.PrepareStatement(ctx, mysql.StatementKeyReferTimeGetAll, query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, richerror.New(op).WithErr(err).
|
return nil, richerror.New(op).WithErr(err).
|
||||||
WithMessage(errmsg.ErrorMsgCantPrepareStatement).WithKind(richerror.KindUnexpected)
|
WithMessage(errmsg.ErrorMsgCantPrepareStatement).WithKind(richerror.KindUnexpected)
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := stmt.QueryContext(ctx)
|
rows, err := stmt.QueryContext(ctx, status)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, richerror.New(op).WithErr(err).
|
return nil, richerror.New(op).WithErr(err).
|
||||||
WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
|
WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,24 @@ package adminrefertimeservice
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/refer_time"
|
param "git.gocasts.ir/ebhomengo/niki/param/admin/refer_time"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s Service) GetAll(ctx context.Context, _ param.GetAllReferTimeRequest) (param.GetAllReferTimeResponse, error) {
|
func (s Service) GetAll(ctx context.Context, req param.GetAllReferTimeRequest) (param.GetAllReferTimeResponse, error) {
|
||||||
const op = "adminrefertimeservice.GetAllReferTime"
|
const op = "adminrefertimeservice.GetAllReferTime"
|
||||||
|
status := entity.ReferTimeActiveStatus
|
||||||
|
|
||||||
referTimes, err := s.repo.GetAll(ctx)
|
if fieldErrors, vErr := s.vld.ValidateGetAll(req); vErr != nil {
|
||||||
|
return param.GetAllReferTimeResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if str, ok := req.Filter["status"].(string); ok {
|
||||||
|
status = entity.ReferTimeStatus(str)
|
||||||
|
}
|
||||||
|
|
||||||
|
referTimes, err := s.repo.GetAll(ctx, status)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return param.GetAllReferTimeResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
return param.GetAllReferTimeResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,21 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
|
validator "git.gocasts.ir/ebhomengo/niki/validator/admin/refer_time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
repo Repository
|
repo Repository
|
||||||
|
vld validator.Validator
|
||||||
}
|
}
|
||||||
type Repository interface {
|
type Repository interface {
|
||||||
Get(ctx context.Context, referTimeID uint) (entity.ReferTime, error)
|
Get(ctx context.Context, referTimeID uint) (entity.ReferTime, error)
|
||||||
GetAll(ctx context.Context) ([]entity.ReferTime, error)
|
GetAll(ctx context.Context, status entity.ReferTimeStatus) ([]entity.ReferTime, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(repo Repository) Service {
|
func New(repo Repository, vld validator.Validator) Service {
|
||||||
return Service{repo: repo}
|
return Service{
|
||||||
|
repo: repo,
|
||||||
|
vld: vld,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,16 @@ package benefactorrefertimeservice
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/refer_time"
|
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/refer_time"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s Service) GetAll(ctx context.Context, _ param.GetAllReferTimeRequest) (param.GetAllReferTimeResponse, error) {
|
func (s Service) GetAll(ctx context.Context, _ param.GetAllReferTimeRequest) (param.GetAllReferTimeResponse, error) {
|
||||||
const op = "benefactorrefertimeservice.GetAllReferTime"
|
const op = "benefactorrefertimeservice.GetAllReferTime"
|
||||||
|
status := entity.ReferTimeActiveStatus
|
||||||
|
|
||||||
referTimes, err := s.repo.GetAll(ctx)
|
referTimes, err := s.repo.GetAll(ctx, status)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return param.GetAllReferTimeResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
return param.GetAllReferTimeResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ type Service struct {
|
||||||
}
|
}
|
||||||
type Repository interface {
|
type Repository interface {
|
||||||
Get(ctx context.Context, referTimeID uint) (entity.ReferTime, error)
|
Get(ctx context.Context, referTimeID uint) (entity.ReferTime, error)
|
||||||
GetAll(ctx context.Context) ([]entity.ReferTime, error)
|
GetAll(ctx context.Context, status entity.ReferTimeStatus) ([]entity.ReferTime, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(repo Repository) Service {
|
func New(repo Repository) Service {
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ import (
|
||||||
adminbenefactorvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/benefactor"
|
adminbenefactorvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/benefactor"
|
||||||
adminkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box"
|
adminkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box"
|
||||||
adminkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box_req"
|
adminkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box_req"
|
||||||
|
adminrefertimevalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/refer_time"
|
||||||
agentkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/agent/kind_box"
|
agentkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/agent/kind_box"
|
||||||
agentkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/agent/kind_box_req"
|
agentkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/agent/kind_box_req"
|
||||||
benefactoraddressvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/address"
|
benefactoraddressvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/address"
|
||||||
|
|
@ -76,7 +77,8 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont
|
||||||
var (
|
var (
|
||||||
AdminAuthSvc = auth.New(cfg.AdminAuth)
|
AdminAuthSvc = auth.New(cfg.AdminAuth)
|
||||||
AdminAuthorizeSvc = adminauthorizationservice.New(adminRepo)
|
AdminAuthorizeSvc = adminauthorizationservice.New(adminRepo)
|
||||||
AdminReferTimeSvc = adminrefertimeservice.New(referTimeRepo)
|
AdminReferTimeVld = adminrefertimevalidator.New()
|
||||||
|
AdminReferTimeSvc = adminrefertimeservice.New(referTimeRepo, AdminReferTimeVld)
|
||||||
AdminAddressSvc = adminaddressservice.New(addressRepo)
|
AdminAddressSvc = adminaddressservice.New(addressRepo)
|
||||||
AdminBenefactorVld = adminbenefactorvalidator.New()
|
AdminBenefactorVld = adminbenefactorvalidator.New()
|
||||||
AdminBenefactorSvc = adminbenefactorservice.New(benefactorRepo, AdminAddressSvc, AdminBenefactorVld)
|
AdminBenefactorSvc = adminbenefactorservice.New(benefactorRepo, AdminAddressSvc, AdminBenefactorVld)
|
||||||
|
|
@ -107,8 +109,6 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont
|
||||||
BenefactorKindBoxReqSvc = benefactorkindboxreqservice.New(kindBoxReqRepo, BenefactorKindBoxReqVld)
|
BenefactorKindBoxReqSvc = benefactorkindboxreqservice.New(kindBoxReqRepo, BenefactorKindBoxReqVld)
|
||||||
BenefactorKindBoxVld = benefactorkindboxvalidator.New(kindBoxRepo, BenefactorSvc, BenefactorAddressSvc, BenefactorReferTimeSvc)
|
BenefactorKindBoxVld = benefactorkindboxvalidator.New(kindBoxRepo, BenefactorSvc, BenefactorAddressSvc, BenefactorReferTimeSvc)
|
||||||
BenefactorKindBoxSvc = benefactorkindboxservice.New(kindBoxRepo, BenefactorKindBoxVld)
|
BenefactorKindBoxSvc = benefactorkindboxservice.New(kindBoxRepo, BenefactorKindBoxVld)
|
||||||
benefactorReferTimeSvc = benefactorrefertimeservice.New(referTimeRepo)
|
|
||||||
adminReferTimeSvc = adminrefertimeservice.New(referTimeRepo)
|
|
||||||
)
|
)
|
||||||
NotificationSvc := notification.New(cfg.NotificationSvc, smsAdapter, AdminKindBoxReqSvc, AdminBenefactorSvc, AdminSvc, AdminKindBoxSvc)
|
NotificationSvc := notification.New(cfg.NotificationSvc, smsAdapter, AdminKindBoxReqSvc, AdminBenefactorSvc, AdminSvc, AdminKindBoxSvc)
|
||||||
|
|
||||||
|
|
@ -128,7 +128,7 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont
|
||||||
BenefactorAddressSvc: BenefactorAddressSvc,
|
BenefactorAddressSvc: BenefactorAddressSvc,
|
||||||
BenefactorSvc: BenefactorSvc,
|
BenefactorSvc: BenefactorSvc,
|
||||||
NotificationSvc: NotificationSvc,
|
NotificationSvc: NotificationSvc,
|
||||||
BenefactorReferTimeSvc: benefactorReferTimeSvc,
|
BenefactorReferTimeSvc: BenefactorReferTimeSvc,
|
||||||
AdminReferTimeSvc: adminReferTimeSvc,
|
AdminReferTimeSvc: AdminReferTimeSvc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
package adminrefertimevalidator
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
param "git.gocasts.ir/ebhomengo/niki/param/admin/refer_time"
|
||||||
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (v Validator) ValidateGetAll(req param.GetAllReferTimeRequest) (map[string]string, error) {
|
||||||
|
const op = "adminrefertimevalidator.ValidateGetAll"
|
||||||
|
|
||||||
|
validFields := []string{"status"}
|
||||||
|
|
||||||
|
if err := validation.ValidateStruct(&req,
|
||||||
|
validation.Field(&req.Filter, validation.By(v.AreFilterFieldsValid(validFields))),
|
||||||
|
); err != nil {
|
||||||
|
fieldErrors := make(map[string]string)
|
||||||
|
|
||||||
|
var errV validation.Errors
|
||||||
|
if errors.As(err, &errV) {
|
||||||
|
for key, value := range errV {
|
||||||
|
if value != nil {
|
||||||
|
fieldErrors[key] = value.Error()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fieldErrors, richerror.New(op).
|
||||||
|
WithMessage(errmsg.ErrorMsgInvalidInput).
|
||||||
|
WithKind(richerror.KindInvalid).
|
||||||
|
WithMeta(map[string]interface{}{"req": req}).
|
||||||
|
WithErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return map[string]string{}, nil
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package adminrefertimevalidator
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"slices"
|
||||||
|
|
||||||
|
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||||
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
|
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Validator struct{}
|
||||||
|
|
||||||
|
func New() Validator {
|
||||||
|
return Validator{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v Validator) AreFilterFieldsValid(validFilters []string) validation.RuleFunc {
|
||||||
|
return func(value interface{}) error {
|
||||||
|
filters, ok := value.(params.FilterRequest)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
||||||
|
}
|
||||||
|
for filter := range filters {
|
||||||
|
if !slices.Contains(validFilters, filter) {
|
||||||
|
return fmt.Errorf(errmsg.ErrorMsgFiltersAreNotValid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue