feat(backend): add custom preferences
This commit is contained in:
parent
e8ea642260
commit
2c71741d7c
8 changed files with 39 additions and 34 deletions
|
@ -40,13 +40,13 @@ func (w *WordStatus) UnmarshalJSON(src []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (w WordStatus) Valid(extra ...WordStatus) bool {
|
||||
func (w WordStatus) Valid(extra CustomPreferences) bool {
|
||||
if w == StatusFavourite || w == StatusOkay || w == StatusJokingly || w == StatusFriendsOnly || w == StatusAvoid {
|
||||
return true
|
||||
}
|
||||
|
||||
for i := range extra {
|
||||
if w == extra[i] {
|
||||
for k := range extra {
|
||||
if string(w) == k {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ type FieldEntry struct {
|
|||
Status WordStatus `json:"status"`
|
||||
}
|
||||
|
||||
func (fe FieldEntry) Validate() string {
|
||||
func (fe FieldEntry) Validate(custom CustomPreferences) string {
|
||||
if fe.Value == "" {
|
||||
return "value cannot be empty"
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ func (fe FieldEntry) Validate() string {
|
|||
return fmt.Sprintf("name must be %d characters or less, is %d", FieldEntryMaxLength, len([]rune(fe.Value)))
|
||||
}
|
||||
|
||||
if !fe.Status.Valid() {
|
||||
if !fe.Status.Valid(custom) {
|
||||
return "status is invalid"
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ type PronounEntry struct {
|
|||
Status WordStatus `json:"status"`
|
||||
}
|
||||
|
||||
func (p PronounEntry) Validate() string {
|
||||
func (p PronounEntry) Validate(custom CustomPreferences) string {
|
||||
if p.Pronouns == "" {
|
||||
return "pronouns cannot be empty"
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ func (p PronounEntry) Validate() string {
|
|||
return fmt.Sprintf("pronouns must be %d characters or less, is %d", FieldEntryMaxLength, len([]rune(p.Pronouns)))
|
||||
}
|
||||
|
||||
if !p.Status.Valid() {
|
||||
if !p.Status.Valid(custom) {
|
||||
return "status is invalid"
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue