amo/common/common.go
2024-05-31 22:19:41 +05:00

45 lines
924 B
Go

package common
import (
"regexp"
)
type Value struct {
Value any `json:"value,omitempty"`
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"`
Values []Value `json:"values"`
}
type CustomFieldsValues []CustomFieldsValue
func (vs CustomFieldsValues) GetByID(
id int,
) (CustomFieldsValue, bool) {
for _, v := range vs {
if v.FieldID == id {
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)
}
}
return ret
}