forked from ebhomengo/niki
25 lines
589 B
Go
25 lines
589 B
Go
|
package validator
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
params "git.gocasts.ir/ebhomengo/niki/param"
|
||
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||
|
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||
|
"slices"
|
||
|
)
|
||
|
|
||
|
func 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
|
||
|
}
|
||
|
}
|