amo/common/common.go

46 lines
924 B
Go
Raw Permalink Normal View History

2024-01-15 00:04:00 +03:00
package common
2024-05-31 20:19:41 +03:00
import (
"regexp"
)
type Value struct {
Value any `json:"value,omitempty"`
2024-01-15 00:04:00 +03:00
EnumID int `json:"enum_id,omitempty"`
Enum string `json:"enum,omitempty"`
}
type CustomFieldsValue struct {
FieldID int `json:"field_id"`
FieldName string `json:"field_name,omitempty"`
FieldCode string `json:"field_code,omitempty"`
FieldType string `json:"field_type,omitempty"`
2024-05-31 20:19:41 +03:00
Values []Value `json:"values"`
2024-01-15 00:04:00 +03:00
}
type CustomFieldsValues []CustomFieldsValue
2024-05-31 20:19:41 +03:00
func (vs CustomFieldsValues) GetByID(
id int,
2024-05-31 20:19:41 +03:00
) (CustomFieldsValue, bool) {
for _, v := range vs {
if v.FieldID == id {
2024-05-31 20:19:41 +03:00
return v, true
}
}
return CustomFieldsValue{}, false
}
func (fields CustomFieldsValues) FilterByNameRegex(
re *regexp.Regexp,
) CustomFieldsValues {
ret := CustomFieldsValues{}
for _, field := range fields {
if re.MatchString(field.FieldName) {
ret = append(ret, field)
}
}
2024-05-31 20:19:41 +03:00
return ret
}
2024-05-31 20:19:41 +03:00