code refactor
This commit is contained in:
+5
-5
@@ -330,7 +330,7 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.WebContext) (any, *errs.Erro
|
||||
userNew.FirstDayOfWeek = *userUpdateReq.FirstDayOfWeek
|
||||
anythingUpdate = true
|
||||
} else {
|
||||
userNew.FirstDayOfWeek = models.WEEKDAY_INVALID
|
||||
userNew.FirstDayOfWeek = core.WEEKDAY_INVALID
|
||||
}
|
||||
|
||||
if userUpdateReq.LongDateFormat != nil && *userUpdateReq.LongDateFormat != user.LongDateFormat {
|
||||
@@ -338,7 +338,7 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.WebContext) (any, *errs.Erro
|
||||
userNew.LongDateFormat = *userUpdateReq.LongDateFormat
|
||||
anythingUpdate = true
|
||||
} else {
|
||||
userNew.LongDateFormat = models.LONG_DATE_FORMAT_INVALID
|
||||
userNew.LongDateFormat = core.LONG_DATE_FORMAT_INVALID
|
||||
}
|
||||
|
||||
if userUpdateReq.ShortDateFormat != nil && *userUpdateReq.ShortDateFormat != user.ShortDateFormat {
|
||||
@@ -346,7 +346,7 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.WebContext) (any, *errs.Erro
|
||||
userNew.ShortDateFormat = *userUpdateReq.ShortDateFormat
|
||||
anythingUpdate = true
|
||||
} else {
|
||||
userNew.ShortDateFormat = models.SHORT_DATE_FORMAT_INVALID
|
||||
userNew.ShortDateFormat = core.SHORT_DATE_FORMAT_INVALID
|
||||
}
|
||||
|
||||
if userUpdateReq.LongTimeFormat != nil && *userUpdateReq.LongTimeFormat != user.LongTimeFormat {
|
||||
@@ -354,7 +354,7 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.WebContext) (any, *errs.Erro
|
||||
userNew.LongTimeFormat = *userUpdateReq.LongTimeFormat
|
||||
anythingUpdate = true
|
||||
} else {
|
||||
userNew.LongTimeFormat = models.LONG_TIME_FORMAT_INVALID
|
||||
userNew.LongTimeFormat = core.LONG_TIME_FORMAT_INVALID
|
||||
}
|
||||
|
||||
if userUpdateReq.ShortTimeFormat != nil && *userUpdateReq.ShortTimeFormat != user.ShortTimeFormat {
|
||||
@@ -362,7 +362,7 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.WebContext) (any, *errs.Erro
|
||||
userNew.ShortTimeFormat = *userUpdateReq.ShortTimeFormat
|
||||
anythingUpdate = true
|
||||
} else {
|
||||
userNew.ShortTimeFormat = models.SHORT_TIME_FORMAT_INVALID
|
||||
userNew.ShortTimeFormat = core.SHORT_TIME_FORMAT_INVALID
|
||||
}
|
||||
|
||||
if userUpdateReq.DecimalSeparator != nil && *userUpdateReq.DecimalSeparator != user.DecimalSeparator {
|
||||
|
||||
@@ -89,7 +89,7 @@ func (l *UserDataCli) AddNewUser(c *core.CliContext, username string, email stri
|
||||
Nickname: nickname,
|
||||
Password: password,
|
||||
DefaultCurrency: defaultCurrency,
|
||||
FirstDayOfWeek: models.WEEKDAY_SUNDAY,
|
||||
FirstDayOfWeek: core.WEEKDAY_SUNDAY,
|
||||
TransactionEditScope: models.TRANSACTION_EDIT_SCOPE_ALL,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package models
|
||||
package core
|
||||
|
||||
import "fmt"
|
||||
|
||||
+22
-22
@@ -93,11 +93,11 @@ type User struct {
|
||||
TransactionEditScope TransactionEditScope `xorm:"TINYINT NOT NULL"`
|
||||
Language string `xorm:"VARCHAR(10)"`
|
||||
DefaultCurrency string `xorm:"VARCHAR(3) NOT NULL"`
|
||||
FirstDayOfWeek WeekDay `xorm:"TINYINT NOT NULL"`
|
||||
LongDateFormat LongDateFormat `xorm:"TINYINT"`
|
||||
ShortDateFormat ShortDateFormat `xorm:"TINYINT"`
|
||||
LongTimeFormat LongTimeFormat `xorm:"TINYINT"`
|
||||
ShortTimeFormat ShortTimeFormat `xorm:"TINYINT"`
|
||||
FirstDayOfWeek core.WeekDay `xorm:"TINYINT NOT NULL"`
|
||||
LongDateFormat core.LongDateFormat `xorm:"TINYINT"`
|
||||
ShortDateFormat core.ShortDateFormat `xorm:"TINYINT"`
|
||||
LongTimeFormat core.LongTimeFormat `xorm:"TINYINT"`
|
||||
ShortTimeFormat core.ShortTimeFormat `xorm:"TINYINT"`
|
||||
DecimalSeparator core.DecimalSeparator `xorm:"TINYINT"`
|
||||
DigitGroupingSymbol core.DigitGroupingSymbol `xorm:"TINYINT"`
|
||||
DigitGrouping core.DigitGroupingType `xorm:"TINYINT"`
|
||||
@@ -124,11 +124,11 @@ type UserBasicInfo struct {
|
||||
TransactionEditScope TransactionEditScope `json:"transactionEditScope"`
|
||||
Language string `json:"language"`
|
||||
DefaultCurrency string `json:"defaultCurrency"`
|
||||
FirstDayOfWeek WeekDay `json:"firstDayOfWeek"`
|
||||
LongDateFormat LongDateFormat `json:"longDateFormat"`
|
||||
ShortDateFormat ShortDateFormat `json:"shortDateFormat"`
|
||||
LongTimeFormat LongTimeFormat `json:"longTimeFormat"`
|
||||
ShortTimeFormat ShortTimeFormat `json:"shortTimeFormat"`
|
||||
FirstDayOfWeek core.WeekDay `json:"firstDayOfWeek"`
|
||||
LongDateFormat core.LongDateFormat `json:"longDateFormat"`
|
||||
ShortDateFormat core.ShortDateFormat `json:"shortDateFormat"`
|
||||
LongTimeFormat core.LongTimeFormat `json:"longTimeFormat"`
|
||||
ShortTimeFormat core.ShortTimeFormat `json:"shortTimeFormat"`
|
||||
DecimalSeparator core.DecimalSeparator `json:"decimalSeparator"`
|
||||
DigitGroupingSymbol core.DigitGroupingSymbol `json:"digitGroupingSymbol"`
|
||||
DigitGrouping core.DigitGroupingType `json:"digitGrouping"`
|
||||
@@ -146,13 +146,13 @@ type UserLoginRequest struct {
|
||||
|
||||
// UserRegisterRequest represents all parameters of user registering request
|
||||
type UserRegisterRequest struct {
|
||||
Username string `json:"username" binding:"required,notBlank,max=32,validUsername"`
|
||||
Email string `json:"email" binding:"required,notBlank,max=100,validEmail"`
|
||||
Nickname string `json:"nickname" binding:"required,notBlank,max=64"`
|
||||
Password string `json:"password" binding:"required,min=6,max=128"`
|
||||
Language string `json:"language" binding:"required,min=2,max=16"`
|
||||
DefaultCurrency string `json:"defaultCurrency" binding:"required,len=3,validCurrency"`
|
||||
FirstDayOfWeek WeekDay `json:"firstDayOfWeek" binding:"min=0,max=6"`
|
||||
Username string `json:"username" binding:"required,notBlank,max=32,validUsername"`
|
||||
Email string `json:"email" binding:"required,notBlank,max=100,validEmail"`
|
||||
Nickname string `json:"nickname" binding:"required,notBlank,max=64"`
|
||||
Password string `json:"password" binding:"required,min=6,max=128"`
|
||||
Language string `json:"language" binding:"required,min=2,max=16"`
|
||||
DefaultCurrency string `json:"defaultCurrency" binding:"required,len=3,validCurrency"`
|
||||
FirstDayOfWeek core.WeekDay `json:"firstDayOfWeek" binding:"min=0,max=6"`
|
||||
TransactionCategoryCreateBatchRequest
|
||||
}
|
||||
|
||||
@@ -184,11 +184,11 @@ type UserProfileUpdateRequest struct {
|
||||
TransactionEditScope *TransactionEditScope `json:"transactionEditScope" binding:"omitempty,min=0,max=6"`
|
||||
Language string `json:"language" binding:"omitempty,min=2,max=16"`
|
||||
DefaultCurrency string `json:"defaultCurrency" binding:"omitempty,len=3,validCurrency"`
|
||||
FirstDayOfWeek *WeekDay `json:"firstDayOfWeek" binding:"omitempty,min=0,max=6"`
|
||||
LongDateFormat *LongDateFormat `json:"longDateFormat" binding:"omitempty,min=0,max=3"`
|
||||
ShortDateFormat *ShortDateFormat `json:"shortDateFormat" binding:"omitempty,min=0,max=3"`
|
||||
LongTimeFormat *LongTimeFormat `json:"longTimeFormat" binding:"omitempty,min=0,max=3"`
|
||||
ShortTimeFormat *ShortTimeFormat `json:"shortTimeFormat" binding:"omitempty,min=0,max=3"`
|
||||
FirstDayOfWeek *core.WeekDay `json:"firstDayOfWeek" binding:"omitempty,min=0,max=6"`
|
||||
LongDateFormat *core.LongDateFormat `json:"longDateFormat" binding:"omitempty,min=0,max=3"`
|
||||
ShortDateFormat *core.ShortDateFormat `json:"shortDateFormat" binding:"omitempty,min=0,max=3"`
|
||||
LongTimeFormat *core.LongTimeFormat `json:"longTimeFormat" binding:"omitempty,min=0,max=3"`
|
||||
ShortTimeFormat *core.ShortTimeFormat `json:"shortTimeFormat" binding:"omitempty,min=0,max=3"`
|
||||
DecimalSeparator *core.DecimalSeparator `json:"decimalSeparator" binding:"omitempty,min=0,max=3"`
|
||||
DigitGroupingSymbol *core.DigitGroupingSymbol `json:"digitGroupingSymbol" binding:"omitempty,min=0,max=4"`
|
||||
DigitGrouping *core.DigitGroupingType `json:"digitGrouping" binding:"omitempty,min=0,max=2"`
|
||||
|
||||
@@ -281,23 +281,23 @@ func (s *UserService) UpdateUser(c core.Context, user *models.User, modifyUserLa
|
||||
updateCols = append(updateCols, "default_currency")
|
||||
}
|
||||
|
||||
if models.WEEKDAY_SUNDAY <= user.FirstDayOfWeek && user.FirstDayOfWeek <= models.WEEKDAY_SATURDAY {
|
||||
if core.WEEKDAY_SUNDAY <= user.FirstDayOfWeek && user.FirstDayOfWeek <= core.WEEKDAY_SATURDAY {
|
||||
updateCols = append(updateCols, "first_day_of_week")
|
||||
}
|
||||
|
||||
if models.LONG_DATE_FORMAT_DEFAULT <= user.LongDateFormat && user.LongDateFormat <= models.LONG_DATE_FORMAT_D_M_YYYY {
|
||||
if core.LONG_DATE_FORMAT_DEFAULT <= user.LongDateFormat && user.LongDateFormat <= core.LONG_DATE_FORMAT_D_M_YYYY {
|
||||
updateCols = append(updateCols, "long_date_format")
|
||||
}
|
||||
|
||||
if models.SHORT_DATE_FORMAT_DEFAULT <= user.ShortDateFormat && user.ShortDateFormat <= models.SHORT_DATE_FORMAT_D_M_YYYY {
|
||||
if core.SHORT_DATE_FORMAT_DEFAULT <= user.ShortDateFormat && user.ShortDateFormat <= core.SHORT_DATE_FORMAT_D_M_YYYY {
|
||||
updateCols = append(updateCols, "short_date_format")
|
||||
}
|
||||
|
||||
if models.LONG_TIME_FORMAT_DEFAULT <= user.LongTimeFormat && user.LongTimeFormat <= models.LONG_TIME_FORMAT_HH_MM_SS_A {
|
||||
if core.LONG_TIME_FORMAT_DEFAULT <= user.LongTimeFormat && user.LongTimeFormat <= core.LONG_TIME_FORMAT_HH_MM_SS_A {
|
||||
updateCols = append(updateCols, "long_time_format")
|
||||
}
|
||||
|
||||
if models.SHORT_TIME_FORMAT_DEFAULT <= user.ShortTimeFormat && user.ShortTimeFormat <= models.SHORT_TIME_FORMAT_HH_MM_A {
|
||||
if core.SHORT_TIME_FORMAT_DEFAULT <= user.ShortTimeFormat && user.ShortTimeFormat <= core.SHORT_TIME_FORMAT_HH_MM_A {
|
||||
updateCols = append(updateCols, "short_time_format")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user