2022-04-25 05:55:05 +00:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CriterionModifier string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// =
|
|
|
|
CriterionModifierEquals CriterionModifier = "EQUALS"
|
|
|
|
// !=
|
|
|
|
CriterionModifierNotEquals CriterionModifier = "NOT_EQUALS"
|
|
|
|
// >
|
|
|
|
CriterionModifierGreaterThan CriterionModifier = "GREATER_THAN"
|
|
|
|
// <
|
|
|
|
CriterionModifierLessThan CriterionModifier = "LESS_THAN"
|
|
|
|
// IS NULL
|
|
|
|
CriterionModifierIsNull CriterionModifier = "IS_NULL"
|
|
|
|
// IS NOT NULL
|
|
|
|
CriterionModifierNotNull CriterionModifier = "NOT_NULL"
|
|
|
|
// INCLUDES ALL
|
|
|
|
CriterionModifierIncludesAll CriterionModifier = "INCLUDES_ALL"
|
|
|
|
CriterionModifierIncludes CriterionModifier = "INCLUDES"
|
|
|
|
CriterionModifierExcludes CriterionModifier = "EXCLUDES"
|
|
|
|
// MATCHES REGEX
|
|
|
|
CriterionModifierMatchesRegex CriterionModifier = "MATCHES_REGEX"
|
|
|
|
// NOT MATCHES REGEX
|
|
|
|
CriterionModifierNotMatchesRegex CriterionModifier = "NOT_MATCHES_REGEX"
|
|
|
|
// >= AND <=
|
|
|
|
CriterionModifierBetween CriterionModifier = "BETWEEN"
|
|
|
|
// < OR >
|
|
|
|
CriterionModifierNotBetween CriterionModifier = "NOT_BETWEEN"
|
|
|
|
)
|
|
|
|
|
|
|
|
var AllCriterionModifier = []CriterionModifier{
|
|
|
|
CriterionModifierEquals,
|
|
|
|
CriterionModifierNotEquals,
|
|
|
|
CriterionModifierGreaterThan,
|
|
|
|
CriterionModifierLessThan,
|
|
|
|
CriterionModifierIsNull,
|
|
|
|
CriterionModifierNotNull,
|
|
|
|
CriterionModifierIncludesAll,
|
|
|
|
CriterionModifierIncludes,
|
|
|
|
CriterionModifierExcludes,
|
|
|
|
CriterionModifierMatchesRegex,
|
|
|
|
CriterionModifierNotMatchesRegex,
|
|
|
|
CriterionModifierBetween,
|
|
|
|
CriterionModifierNotBetween,
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e CriterionModifier) IsValid() bool {
|
|
|
|
switch e {
|
|
|
|
case CriterionModifierEquals, CriterionModifierNotEquals, CriterionModifierGreaterThan, CriterionModifierLessThan, CriterionModifierIsNull, CriterionModifierNotNull, CriterionModifierIncludesAll, CriterionModifierIncludes, CriterionModifierExcludes, CriterionModifierMatchesRegex, CriterionModifierNotMatchesRegex, CriterionModifierBetween, CriterionModifierNotBetween:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e CriterionModifier) String() string {
|
|
|
|
return string(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *CriterionModifier) UnmarshalGQL(v interface{}) error {
|
|
|
|
str, ok := v.(string)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("enums must be strings")
|
|
|
|
}
|
|
|
|
|
|
|
|
*e = CriterionModifier(str)
|
|
|
|
if !e.IsValid() {
|
|
|
|
return fmt.Errorf("%s is not a valid CriterionModifier", str)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e CriterionModifier) MarshalGQL(w io.Writer) {
|
|
|
|
fmt.Fprint(w, strconv.Quote(e.String()))
|
|
|
|
}
|
|
|
|
|
|
|
|
type StringCriterionInput struct {
|
|
|
|
Value string `json:"value"`
|
|
|
|
Modifier CriterionModifier `json:"modifier"`
|
|
|
|
}
|
|
|
|
|
2022-11-08 03:09:03 +00:00
|
|
|
func (i StringCriterionInput) ValidModifier() bool {
|
|
|
|
switch i.Modifier {
|
|
|
|
case CriterionModifierEquals, CriterionModifierNotEquals, CriterionModifierIncludes, CriterionModifierExcludes, CriterionModifierMatchesRegex, CriterionModifierNotMatchesRegex,
|
|
|
|
CriterionModifierIsNull, CriterionModifierNotNull:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-04-25 05:55:05 +00:00
|
|
|
type IntCriterionInput struct {
|
|
|
|
Value int `json:"value"`
|
|
|
|
Value2 *int `json:"value2"`
|
|
|
|
Modifier CriterionModifier `json:"modifier"`
|
|
|
|
}
|
|
|
|
|
2022-11-08 03:09:03 +00:00
|
|
|
func (i IntCriterionInput) ValidModifier() bool {
|
|
|
|
switch i.Modifier {
|
|
|
|
case CriterionModifierEquals, CriterionModifierNotEquals, CriterionModifierGreaterThan, CriterionModifierLessThan, CriterionModifierIsNull, CriterionModifierNotNull, CriterionModifierBetween, CriterionModifierNotBetween:
|
2023-05-24 03:19:35 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
type FloatCriterionInput struct {
|
|
|
|
Value float64 `json:"value"`
|
|
|
|
Value2 *float64 `json:"value2"`
|
|
|
|
Modifier CriterionModifier `json:"modifier"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i FloatCriterionInput) ValidModifier() bool {
|
|
|
|
switch i.Modifier {
|
|
|
|
case CriterionModifierEquals, CriterionModifierNotEquals, CriterionModifierGreaterThan, CriterionModifierLessThan, CriterionModifierIsNull, CriterionModifierNotNull, CriterionModifierBetween, CriterionModifierNotBetween:
|
2022-11-08 03:09:03 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-04-25 05:55:05 +00:00
|
|
|
type ResolutionCriterionInput struct {
|
|
|
|
Value ResolutionEnum `json:"value"`
|
|
|
|
Modifier CriterionModifier `json:"modifier"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type HierarchicalMultiCriterionInput struct {
|
|
|
|
Value []string `json:"value"`
|
|
|
|
Modifier CriterionModifier `json:"modifier"`
|
|
|
|
Depth *int `json:"depth"`
|
2023-05-25 02:03:49 +00:00
|
|
|
Excludes []string `json:"excludes"`
|
2022-04-25 05:55:05 +00:00
|
|
|
}
|
|
|
|
|
2023-06-06 03:01:50 +00:00
|
|
|
func (i HierarchicalMultiCriterionInput) CombineExcludes() HierarchicalMultiCriterionInput {
|
|
|
|
ii := i
|
|
|
|
if ii.Modifier == CriterionModifierExcludes {
|
|
|
|
ii.Modifier = CriterionModifierIncludesAll
|
|
|
|
ii.Excludes = append(ii.Excludes, ii.Value...)
|
|
|
|
ii.Value = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return ii
|
|
|
|
}
|
|
|
|
|
2022-04-25 05:55:05 +00:00
|
|
|
type MultiCriterionInput struct {
|
|
|
|
Value []string `json:"value"`
|
|
|
|
Modifier CriterionModifier `json:"modifier"`
|
2023-05-25 02:03:49 +00:00
|
|
|
Excludes []string `json:"excludes"`
|
2022-04-25 05:55:05 +00:00
|
|
|
}
|
2022-11-15 00:52:05 +00:00
|
|
|
|
|
|
|
type DateCriterionInput struct {
|
|
|
|
Value string `json:"value"`
|
|
|
|
Value2 *string `json:"value2"`
|
|
|
|
Modifier CriterionModifier `json:"modifier"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type TimestampCriterionInput struct {
|
|
|
|
Value string `json:"value"`
|
|
|
|
Value2 *string `json:"value2"`
|
|
|
|
Modifier CriterionModifier `json:"modifier"`
|
|
|
|
}
|
2023-04-17 05:36:51 +00:00
|
|
|
|
|
|
|
type PhashDistanceCriterionInput struct {
|
|
|
|
Value string `json:"value"`
|
|
|
|
Modifier CriterionModifier `json:"modifier"`
|
|
|
|
Distance *int `json:"distance"`
|
|
|
|
}
|
2024-01-16 02:50:17 +00:00
|
|
|
|
|
|
|
type OrientationCriterionInput struct {
|
|
|
|
Value []OrientationEnum `json:"value"`
|
|
|
|
}
|