2024-07-21 13:10:22 +00:00
|
|
|
package validator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-07-24 23:45:04 +00:00
|
|
|
"slices"
|
|
|
|
|
2024-07-21 13:10:22 +00:00
|
|
|
params "git.gocasts.ir/ebhomengo/niki/param"
|
|
|
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
|
|
|
validation "github.com/go-ozzo/ozzo-validation/v4"
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-07-21 13:10:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|