|
@@ -1,38 +1,5 @@
|
|
|
package rest
|
|
|
|
|
|
-import (
|
|
|
- "fmt"
|
|
|
-
|
|
|
- "git.ali33.ru/fcg-xvii/go-tools/json"
|
|
|
-)
|
|
|
-
|
|
|
-func parseCondition(m json.Map, index int) (*Condition, error) {
|
|
|
- errPrefix := func(errData string) error {
|
|
|
- return fmt.Errorf("[%v]: %s", index, errData)
|
|
|
- }
|
|
|
- cond := Condition{
|
|
|
- Field: m.String("field", ""),
|
|
|
- Logic: ConditionLogic(m.String("logic", "")),
|
|
|
- Operator: ConditionOperator(m.String("operator", "")),
|
|
|
- Value: m["value"],
|
|
|
- }
|
|
|
- if !cond.IsValid() {
|
|
|
- if len(cond.Field) == 0 {
|
|
|
- return nil, errPrefix("empty field name")
|
|
|
- } else if !cond.Operator.IsValid() {
|
|
|
- return nil, errPrefix(fmt.Sprintf("unexpected operator [%s]", cond.Operator))
|
|
|
- } else if !cond.Operator.IsValid() {
|
|
|
- return nil, errPrefix(fmt.Sprintf("unexpected logic [%s]", cond.Logic))
|
|
|
- } else {
|
|
|
- return nil, errPrefix("unexpected error")
|
|
|
- }
|
|
|
- }
|
|
|
- return &cond, nil
|
|
|
-}
|
|
|
-
|
|
|
-//////////////////////////////////////////////////////////////////////////////
|
|
|
-
|
|
|
-// swagger:model ConditionOperator
|
|
|
type ConditionOperator string
|
|
|
|
|
|
const (
|
|
@@ -68,7 +35,6 @@ const (
|
|
|
LogicAND = "and"
|
|
|
)
|
|
|
|
|
|
-// swagger:model ConditionLogic
|
|
|
type ConditionLogic string
|
|
|
|
|
|
func (s ConditionLogic) IsValid() bool {
|
|
@@ -84,7 +50,6 @@ func (s ConditionLogic) IsValid() bool {
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-// swagger:model Condition
|
|
|
type Condition struct {
|
|
|
Field string
|
|
|
Logic ConditionLogic
|