refactor: Add validation and creation methods for custom profile attributes

This commit is contained in:
Julien Tant
2025-02-12 13:18:49 -07:00
committed by Julien Tant (aider)
parent eac47527d2
commit 35e29a0dfd
@@ -17,24 +17,64 @@ const (
)
const (
CustomProfileAttributesValueTypeNone = ""
CustomProfileAttributesValueTypeEmail = "email"
CustomProfileAttributesValueTypeURL = "url"
CustomProfileAttributesValueTypePhone = "phone"
)
func IsKnownCustomProfilteAttributesValueType(valueType string) bool {
switch valueType {
case CustomProfileAttributesValueTypeEmail,
CustomProfileAttributesValueTypeURL,
CustomProfileAttributesValueTypePhone:
return true
}
return false
}
const (
CustomProfileAttributesVisibilityHidden = "hidden"
CustomProfileAttributesVisibilityWhenSet = "when_set"
CustomProfileAttributesVisibilityAlways = "always"
)
func IsKnownCustomProfilteAttributesVisibility(visibility string) bool {
switch visibility {
case CustomProfileAttributesVisibilityHidden,
CustomProfileAttributesVisibilityWhenSet,
CustomProfileAttributesVisibilityAlways:
return true
}
return false
}
type CustomProfileAttributesSelectOption struct {
ID string
Name string
Color string
}
func NewCustomProfileAttributesSelectOptionFromMap(m map[string]any) CustomProfileAttributesSelectOption {
name := ""
color := ""
if v, ok := m["name"]; ok {
if vStr, ok := v.(string); ok {
name = vStr
}
}
if v, ok := m["color"]; ok {
if vStr, ok := v.(string); ok {
color = vStr
}
}
return NewCustomProfileAttributesSelectOption(name, color)
}
func NewCustomProfileAttributesSelectOption(name, color string) CustomProfileAttributesSelectOption {
return CustomProfileAttributesSelectOption{
ID: NewId(),