move currency display type to user settings
This commit is contained in:
@@ -361,6 +361,14 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.Context) (any, *errs.Error)
|
||||
userNew.DigitGrouping = models.DIGIT_GROUPING_TYPE_INVALID
|
||||
}
|
||||
|
||||
if userUpdateReq.CurrencyDisplayType != nil && *userUpdateReq.CurrencyDisplayType != user.CurrencyDisplayType {
|
||||
user.CurrencyDisplayType = *userUpdateReq.CurrencyDisplayType
|
||||
userNew.CurrencyDisplayType = *userUpdateReq.CurrencyDisplayType
|
||||
anythingUpdate = true
|
||||
} else {
|
||||
userNew.CurrencyDisplayType = models.CURRENCY_DISPLAY_TYPE_INVALID
|
||||
}
|
||||
|
||||
if modifyUserLanguage || userNew.DecimalSeparator != models.DECIMAL_SEPARATOR_INVALID || userNew.DigitGroupingSymbol != models.DIGIT_GROUPING_SYMBOL_INVALID {
|
||||
decimalSeparator := userNew.DecimalSeparator
|
||||
digitGroupingSymbol := userNew.DigitGroupingSymbol
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package models
|
||||
|
||||
import "fmt"
|
||||
|
||||
// CurrencyDisplayType represents the display type of amount with currency
|
||||
type CurrencyDisplayType byte
|
||||
|
||||
// Currency Display Type
|
||||
const (
|
||||
CURRENCY_DISPLAY_TYPE_DEFAULT CurrencyDisplayType = 0
|
||||
CURRENCY_DISPLAY_TYPE_NONE CurrencyDisplayType = 1
|
||||
CURRENCY_DISPLAY_TYPE_SYMBOL_BEFORE_AMOUNT CurrencyDisplayType = 2
|
||||
CURRENCY_DISPLAY_TYPE_SYMBOL_AFTER_AMOUNT CurrencyDisplayType = 3
|
||||
CURRENCY_DISPLAY_TYPE_CODE_BEFORE_AMOUNT CurrencyDisplayType = 4
|
||||
CURRENCY_DISPLAY_TYPE_CODE_AFTER_AMOUNT CurrencyDisplayType = 5
|
||||
CURRENCY_DISPLAY_TYPE_NAME_BEFORE_AMOUNT CurrencyDisplayType = 6
|
||||
CURRENCY_DISPLAY_TYPE_NAME_AFTER_AMOUNT CurrencyDisplayType = 7
|
||||
CURRENCY_DISPLAY_TYPE_INVALID CurrencyDisplayType = 255
|
||||
)
|
||||
|
||||
// String returns a textual representation of the currency display type enum
|
||||
func (d CurrencyDisplayType) String() string {
|
||||
switch d {
|
||||
case CURRENCY_DISPLAY_TYPE_DEFAULT:
|
||||
return "Default"
|
||||
case CURRENCY_DISPLAY_TYPE_NONE:
|
||||
return "None"
|
||||
case CURRENCY_DISPLAY_TYPE_SYMBOL_BEFORE_AMOUNT:
|
||||
return "Symbol Before Amount"
|
||||
case CURRENCY_DISPLAY_TYPE_SYMBOL_AFTER_AMOUNT:
|
||||
return "Symbol After Amount"
|
||||
case CURRENCY_DISPLAY_TYPE_CODE_BEFORE_AMOUNT:
|
||||
return "Code Before Amount"
|
||||
case CURRENCY_DISPLAY_TYPE_CODE_AFTER_AMOUNT:
|
||||
return "Code After Amount"
|
||||
case CURRENCY_DISPLAY_TYPE_NAME_BEFORE_AMOUNT:
|
||||
return "Name Before Amount"
|
||||
case CURRENCY_DISPLAY_TYPE_NAME_AFTER_AMOUNT:
|
||||
return "Name After Amount"
|
||||
case CURRENCY_DISPLAY_TYPE_INVALID:
|
||||
return "Invalid"
|
||||
default:
|
||||
return fmt.Sprintf("Invalid(%d)", int(d))
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,7 @@ type User struct {
|
||||
DecimalSeparator DecimalSeparator `xorm:"TINYINT"`
|
||||
DigitGroupingSymbol DigitGroupingSymbol `xorm:"TINYINT"`
|
||||
DigitGrouping DigitGroupingType `xorm:"TINYINT"`
|
||||
CurrencyDisplayType CurrencyDisplayType `xorm:"TINYINT"`
|
||||
Disabled bool
|
||||
Deleted bool `xorm:"NOT NULL"`
|
||||
EmailVerified bool `xorm:"NOT NULL"`
|
||||
@@ -95,6 +96,7 @@ type UserBasicInfo struct {
|
||||
DecimalSeparator DecimalSeparator `json:"decimalSeparator"`
|
||||
DigitGroupingSymbol DigitGroupingSymbol `json:"digitGroupingSymbol"`
|
||||
DigitGrouping DigitGroupingType `json:"digitGrouping"`
|
||||
CurrencyDisplayType CurrencyDisplayType `json:"currencyDisplayType"`
|
||||
EmailVerified bool `json:"emailVerified"`
|
||||
}
|
||||
|
||||
@@ -151,6 +153,7 @@ type UserProfileUpdateRequest struct {
|
||||
DecimalSeparator *DecimalSeparator `json:"decimalSeparator" binding:"omitempty,min=0,max=3"`
|
||||
DigitGroupingSymbol *DigitGroupingSymbol `json:"digitGroupingSymbol" binding:"omitempty,min=0,max=4"`
|
||||
DigitGrouping *DigitGroupingType `json:"digitGrouping" binding:"omitempty,min=0,max=2"`
|
||||
CurrencyDisplayType *CurrencyDisplayType `json:"currencyDisplayType" binding:"omitempty,min=0,max=7"`
|
||||
}
|
||||
|
||||
// UserProfileUpdateResponse represents the data returns to frontend after updating profile
|
||||
@@ -178,6 +181,7 @@ type UserProfileResponse struct {
|
||||
DecimalSeparator DecimalSeparator `json:"decimalSeparator"`
|
||||
DigitGroupingSymbol DigitGroupingSymbol `json:"digitGroupingSymbol"`
|
||||
DigitGrouping DigitGroupingType `json:"digitGrouping"`
|
||||
CurrencyDisplayType CurrencyDisplayType `json:"currencyDisplayType"`
|
||||
EmailVerified bool `json:"emailVerified"`
|
||||
LastLoginAt int64 `json:"lastLoginAt"`
|
||||
}
|
||||
@@ -244,6 +248,7 @@ func (u *User) ToUserBasicInfo() *UserBasicInfo {
|
||||
DecimalSeparator: u.DecimalSeparator,
|
||||
DigitGroupingSymbol: u.DigitGroupingSymbol,
|
||||
DigitGrouping: u.DigitGrouping,
|
||||
CurrencyDisplayType: u.CurrencyDisplayType,
|
||||
EmailVerified: u.EmailVerified,
|
||||
}
|
||||
}
|
||||
@@ -268,6 +273,7 @@ func (u *User) ToUserProfileResponse() *UserProfileResponse {
|
||||
DecimalSeparator: u.DecimalSeparator,
|
||||
DigitGroupingSymbol: u.DigitGroupingSymbol,
|
||||
DigitGrouping: u.DigitGrouping,
|
||||
CurrencyDisplayType: u.CurrencyDisplayType,
|
||||
EmailVerified: u.EmailVerified,
|
||||
LastLoginAt: u.LastLoginUnixTime,
|
||||
}
|
||||
|
||||
@@ -260,6 +260,10 @@ func (s *UserService) UpdateUser(c *core.Context, user *models.User, modifyUserL
|
||||
updateCols = append(updateCols, "digit_grouping")
|
||||
}
|
||||
|
||||
if models.CURRENCY_DISPLAY_TYPE_DEFAULT <= user.CurrencyDisplayType && user.CurrencyDisplayType <= models.CURRENCY_DISPLAY_TYPE_NAME_AFTER_AMOUNT {
|
||||
updateCols = append(updateCols, "currency_display_type")
|
||||
}
|
||||
|
||||
user.UpdatedUnixTime = now
|
||||
updateCols = append(updateCols, "updated_unix_time")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user