1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-01 17:38:37 +00:00

Improve API

This commit is contained in:
Frédéric Guillot 2017-12-24 18:04:34 -08:00
parent 3f473e4a09
commit d5b8f2fb88
15 changed files with 238 additions and 110 deletions

View file

@ -37,21 +37,17 @@ func (u User) ValidateUserCreation() error {
return u.ValidatePassword()
}
// ValidateUserModification validates user for modification.
// ValidateUserModification validates user modification payload.
func (u User) ValidateUserModification() error {
if u.ID <= 0 {
return errors.New("The ID is mandatory")
if u.Theme != "" {
return ValidateTheme(u.Theme)
}
if u.Username == "" {
return errors.New("The username is mandatory")
if u.Password != "" {
return u.ValidatePassword()
}
if err := u.ValidatePassword(); err != nil {
return err
}
return ValidateTheme(u.Theme)
return nil
}
// ValidateUserLogin validates user credential requirements.
@ -78,11 +74,11 @@ func (u User) ValidatePassword() error {
// Merge update the current user with another user.
func (u *User) Merge(override *User) {
if u.Username != override.Username {
if override.Username != "" && u.Username != override.Username {
u.Username = override.Username
}
if u.Password != override.Password {
if override.Password != "" && u.Password != override.Password {
u.Password = override.Password
}
@ -90,15 +86,15 @@ func (u *User) Merge(override *User) {
u.IsAdmin = override.IsAdmin
}
if u.Theme != override.Theme {
if override.Theme != "" && u.Theme != override.Theme {
u.Theme = override.Theme
}
if u.Language != override.Language {
if override.Language != "" && u.Language != override.Language {
u.Language = override.Language
}
if u.Timezone != override.Timezone {
if override.Timezone != "" && u.Timezone != override.Timezone {
u.Timezone = override.Timezone
}
}