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"
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ type Field struct {
|
|||
}
|
||||
|
||||
// Validate validates this field. If it is invalid, a non-empty string is returned as error message.
|
||||
func (f Field) Validate() string {
|
||||
func (f Field) Validate(custom CustomPreferences) string {
|
||||
if f.Name == "" {
|
||||
return "name cannot be empty"
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ func (f Field) Validate() string {
|
|||
return fmt.Sprintf("entries.%d: max length is %d characters, length is %d", i, FieldEntryMaxLength, length)
|
||||
}
|
||||
|
||||
if !entry.Status.Valid() {
|
||||
if !entry.Status.Valid(custom) {
|
||||
return fmt.Sprintf("entries.%d: status is invalid", i)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -498,8 +498,9 @@ func (db *DB) UpdateUser(
|
|||
memberTitle *string, listPrivate *bool,
|
||||
links *[]string,
|
||||
avatar *string,
|
||||
customPreferences *CustomPreferences,
|
||||
) (u User, err error) {
|
||||
if displayName == nil && bio == nil && links == nil && avatar == nil && memberTitle == nil && listPrivate == nil {
|
||||
if displayName == nil && bio == nil && links == nil && avatar == nil && memberTitle == nil && listPrivate == nil && customPreferences == nil {
|
||||
sql, args, err := sq.Select("*").From("users").Where("id = ?", id).ToSql()
|
||||
if err != nil {
|
||||
return u, errors.Wrap(err, "building sql")
|
||||
|
@ -541,6 +542,9 @@ func (db *DB) UpdateUser(
|
|||
if listPrivate != nil {
|
||||
builder = builder.Set("list_private", *listPrivate)
|
||||
}
|
||||
if customPreferences != nil {
|
||||
builder = builder.Set("custom_preferences", *customPreferences)
|
||||
}
|
||||
|
||||
if avatar != nil {
|
||||
if *avatar == "" {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue