1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package rest
- type ConditionOperator string
- const (
- OperatorEqual = "="
- OperatorNotEqual = "!="
- OperatorMore = ">"
- OperatorLess = "<"
- OperatorMoreEqual = ">="
- OperatorLessEqual = "<="
- OperatorLike = "like"
- )
- func (s ConditionOperator) IsValid() bool {
- switch s {
- case OperatorEqual:
- case OperatorNotEqual:
- case OperatorMore:
- case OperatorLess:
- case OperatorMoreEqual:
- case OperatorLessEqual:
- case OperatorLike:
- default:
- return false
- }
- return true
- }
- //////////////////////////////////////////////////////////////////////////////
- const (
- LogicEmpty = ""
- LogicOR = "or"
- LogicAND = "and"
- )
- type ConditionLogic string
- func (s ConditionLogic) IsValid() bool {
- switch s {
- case LogicEmpty:
- case LogicOR:
- case LogicAND:
- default:
- return false
- }
- return true
- }
- //////////////////////////////////////////////////////////////////////////////
- type Condition struct {
- Field string
- Logic ConditionLogic
- Operator ConditionOperator
- Value any
- }
- func (s *Condition) IsValid() bool {
- return len(s.Field) > 0 && s.Logic.IsValid() && s.Operator.IsValid()
- }
- //////////////////////////////////////////////////////////////////////////////
- type ConditionList []*Condition
- func (s *ConditionList) FieldExists(name string) bool {
- for _, v := range *s {
- if v.Field == name {
- return true
- }
- }
- return false
- }
- func (s *ConditionList) FieldsRemove(toRemove []string) {
- toRemoveMap := make(map[string]struct{})
- for _, item := range toRemove {
- toRemoveMap[item] = struct{}{}
- }
- var result ConditionList
- for _, item := range *s {
- if _, found := toRemoveMap[item.Field]; !found {
- result = append(result, item)
- }
- }
- *s = result
- }
|