mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-17 08:14:25 +08:00
add default currency option in user profile
This commit is contained in:
@@ -42,6 +42,7 @@ func (a *UsersApi) UserRegisterHandler(c *core.Context) (interface{}, *errs.Erro
|
||||
Email: userRegisterReq.Email,
|
||||
Nickname: userRegisterReq.Nickname,
|
||||
Password: userRegisterReq.Password,
|
||||
DefaultCurrency: userRegisterReq.DefaultCurrency,
|
||||
}
|
||||
|
||||
err = a.users.CreateUser(user)
|
||||
@@ -92,6 +93,7 @@ func (a *UsersApi) UserProfileHandler(c *core.Context) (interface{}, *errs.Error
|
||||
Email: user.Email,
|
||||
Nickname: user.Nickname,
|
||||
Type: user.Type,
|
||||
DefaultCurrency: user.DefaultCurrency,
|
||||
CreatedAt: user.CreatedUnixTime,
|
||||
UpdatedAt: user.UpdatedUnixTime,
|
||||
LastLoginAt: user.LastLoginUnixTime,
|
||||
@@ -151,6 +153,12 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.Context) (interface{}, *errs
|
||||
userUpdateReq.Nickname = ""
|
||||
}
|
||||
|
||||
if userUpdateReq.DefaultCurrency != "" && userUpdateReq.DefaultCurrency != user.DefaultCurrency {
|
||||
anythingUpdate = true
|
||||
} else {
|
||||
userUpdateReq.DefaultCurrency = ""
|
||||
}
|
||||
|
||||
if !anythingUpdate {
|
||||
return nil, errs.ErrNothingWillBeUpdated
|
||||
}
|
||||
@@ -158,6 +166,7 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.Context) (interface{}, *errs
|
||||
user.Email = userUpdateReq.Email
|
||||
user.Password = userUpdateReq.Password
|
||||
user.Nickname = userUpdateReq.Nickname
|
||||
user.DefaultCurrency = userUpdateReq.DefaultCurrency
|
||||
|
||||
keyProfileUpdated, err := a.users.UpdateUser(user)
|
||||
|
||||
|
||||
@@ -44,3 +44,7 @@ func GetParameterInvalidUsernameMessage(field string) string {
|
||||
func GetParameterInvalidEmailMessage(field string) string {
|
||||
return fmt.Sprintf("parameter \"%s\" is invalid email format", field)
|
||||
}
|
||||
|
||||
func GetParameterInvalidCurrencylMessage(field string) string {
|
||||
return fmt.Sprintf("parameter \"%s\" is invalid currency", field)
|
||||
}
|
||||
|
||||
+20
-16
@@ -17,6 +17,7 @@ type User struct {
|
||||
Salt string `xorm:"VARCHAR(10) NOT NULL"`
|
||||
Rands string `xorm:"VARCHAR(10) NOT NULL"`
|
||||
Type UserType `xorm:"TINYINT NOT NULL"`
|
||||
DefaultCurrency string `xorm:"VARCHAR(3) NOT NULL"`
|
||||
IsAdmin bool `xorm:"NOT NULL"`
|
||||
Deleted bool `xorm:"NOT NULL"`
|
||||
EmailVerified bool `xorm:"NOT NULL"`
|
||||
@@ -32,26 +33,29 @@ type UserLoginRequest struct {
|
||||
}
|
||||
|
||||
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"`
|
||||
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"`
|
||||
DefaultCurrency string `json:"defaultCurrency" binding:"required,len=3,validCurrency"`
|
||||
}
|
||||
|
||||
type UserProfileUpdateRequest struct {
|
||||
Email string `json:"email" binding:"omitempty,notBlank,max=100,validEmail"`
|
||||
Nickname string `json:"nickname" binding:"omitempty,notBlank,max=64"`
|
||||
Password string `json:"password" binding:"omitempty,min=6,max=128"`
|
||||
OldPassword string `json:"oldPassword" binding:"omitempty,min=6,max=128"`
|
||||
Email string `json:"email" binding:"omitempty,notBlank,max=100,validEmail"`
|
||||
Nickname string `json:"nickname" binding:"omitempty,notBlank,max=64"`
|
||||
Password string `json:"password" binding:"omitempty,min=6,max=128"`
|
||||
OldPassword string `json:"oldPassword" binding:"omitempty,min=6,max=128"`
|
||||
DefaultCurrency string `json:"defaultCurrency" binding:"required,len=3,validCurrency"`
|
||||
}
|
||||
|
||||
type UserProfileResponse struct {
|
||||
Uid string `json:"uid"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
Nickname string `json:"nickname"`
|
||||
Type UserType `json:"type"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
LastLoginAt int64 `json:"lastLoginAt"`
|
||||
Uid string `json:"uid"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
Nickname string `json:"nickname"`
|
||||
Type UserType `json:"type"`
|
||||
DefaultCurrency string `json:"defaultCurrency"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
LastLoginAt int64 `json:"lastLoginAt"`
|
||||
}
|
||||
|
||||
@@ -174,6 +174,10 @@ func (s *UserService) UpdateUser(user *models.User) (keyProfileUpdated bool, err
|
||||
updateCols = append(updateCols, "nickname")
|
||||
}
|
||||
|
||||
if user.DefaultCurrency != "" {
|
||||
updateCols = append(updateCols, "default_currency")
|
||||
}
|
||||
|
||||
user.UpdatedUnixTime = now
|
||||
updateCols = append(updateCols, "updated_unix_time")
|
||||
|
||||
|
||||
@@ -59,6 +59,8 @@ func getValidationErrorText(err validator.FieldError) string {
|
||||
return errs.GetParameterInvalidUsernameMessage(fieldName)
|
||||
case "validEmail":
|
||||
return errs.GetParameterInvalidEmailMessage(fieldName)
|
||||
case "validCurrency":
|
||||
return errs.GetParameterInvalidCurrencylMessage(fieldName)
|
||||
}
|
||||
|
||||
return errs.GetParameterInvalidMessage(fieldName)
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
package validators
|
||||
|
||||
import (
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
// ISO 4217
|
||||
var ALL_CURRENCY_NAMES = map[string]bool {
|
||||
"AED": true, //UAE Dirham
|
||||
"AFN": true, //Afghani
|
||||
"ALL": true, //Lek
|
||||
"AMD": true, //Armenian Dram
|
||||
"ANG": true, //Netherlands Antillean Guilder
|
||||
"AOA": true, //Kwanza
|
||||
"ARS": true, //Argentine Peso
|
||||
"AUD": true, //Australian Dollar
|
||||
"AWG": true, //Aruban Florin
|
||||
"AZN": true, //Azerbaijan Manat
|
||||
"BAM": true, //Convertible Mark
|
||||
"BBD": true, //Barbados Dollar
|
||||
"BDT": true, //Taka
|
||||
"BGN": true, //Bulgarian Lev
|
||||
"BHD": true, //Bahraini Dinar
|
||||
"BIF": true, //Burundi Franc
|
||||
"BMD": true, //Bermudian Dollar
|
||||
"BND": true, //Brunei Dollar
|
||||
"BOB": true, //Boliviano
|
||||
"BRL": true, //Brazilian Real
|
||||
"BSD": true, //Bahamian Dollar
|
||||
"BTN": true, //Ngultrum
|
||||
"BWP": true, //Pula
|
||||
"BYN": true, //Belarusian Ruble
|
||||
"BZD": true, //Belize Dollar
|
||||
"CAD": true, //Canadian Dollar
|
||||
"CDF": true, //Congolese Franc
|
||||
"CHF": true, //Swiss Franc
|
||||
"CLP": true, //Chilean Peso
|
||||
"CNY": true, //Yuan Renminbi
|
||||
"COP": true, //Colombian Peso
|
||||
"CRC": true, //Costa Rican Colon
|
||||
"CUC": true, //Peso Convertible
|
||||
"CUP": true, //Cuban Peso
|
||||
"CVE": true, //Cabo Verde Escudo
|
||||
"CZK": true, //Czech Koruna
|
||||
"DJF": true, //Djibouti Franc
|
||||
"DKK": true, //Danish Krone
|
||||
"DOP": true, //Dominican Peso
|
||||
"DZD": true, //Algerian Dinar
|
||||
"EGP": true, //Egyptian Pound
|
||||
"ERN": true, //Nakfa
|
||||
"ETB": true, //Ethiopian Birr
|
||||
"EUR": true, //Euro
|
||||
"FJD": true, //Fiji Dollar
|
||||
"FKP": true, //Falkland Islands Pound
|
||||
"GBP": true, //Pound Sterling
|
||||
"GEL": true, //Lari
|
||||
"GHS": true, //Ghana Cedi
|
||||
"GIP": true, //Gibraltar Pound
|
||||
"GMD": true, //Dalasi
|
||||
"GNF": true, //Guinean Franc
|
||||
"GTQ": true, //Quetzal
|
||||
"GYD": true, //Guyana Dollar
|
||||
"HKD": true, //Hong Kong Dollar
|
||||
"HNL": true, //Lempira
|
||||
"HRK": true, //Kuna
|
||||
"HTG": true, //Gourde
|
||||
"HUF": true, //Forint
|
||||
"IDR": true, //Rupiah
|
||||
"ILS": true, //New Israeli Sheqel
|
||||
"INR": true, //Indian Rupee
|
||||
"IQD": true, //Iraqi Dinar
|
||||
"IRR": true, //Iranian Rial
|
||||
"ISK": true, //Iceland Krona
|
||||
"JMD": true, //Jamaican Dollar
|
||||
"JOD": true, //Jordanian Dinar
|
||||
"JPY": true, //Yen
|
||||
"KES": true, //Kenyan Shilling
|
||||
"KGS": true, //Som
|
||||
"KHR": true, //Riel
|
||||
"KMF": true, //Comorian Franc
|
||||
"KPW": true, //North Korean Won
|
||||
"KRW": true, //Won
|
||||
"KWD": true, //Kuwaiti Dinar
|
||||
"KYD": true, //Cayman Islands Dollar
|
||||
"KZT": true, //Tenge
|
||||
"LAK": true, //Lao Kip
|
||||
"LBP": true, //Lebanese Pound
|
||||
"LKR": true, //Sri Lanka Rupee
|
||||
"LRD": true, //Liberian Dollar
|
||||
"LSL": true, //Loti
|
||||
"LYD": true, //Libyan Dinar
|
||||
"MAD": true, //Moroccan Dirham
|
||||
"MDL": true, //Moldovan Leu
|
||||
"MGA": true, //Malagasy Ariary
|
||||
"MKD": true, //Denar
|
||||
"MMK": true, //Kyat
|
||||
"MNT": true, //Tugrik
|
||||
"MOP": true, //Pataca
|
||||
"MRU": true, //Ouguiya
|
||||
"MUR": true, //Mauritius Rupee
|
||||
"MVR": true, //Rufiyaa
|
||||
"MWK": true, //Malawi Kwacha
|
||||
"MXN": true, //Mexican Peso
|
||||
"MYR": true, //Malaysian Ringgit
|
||||
"MZN": true, //Mozambique Metical
|
||||
"NAD": true, //Namibia Dollar
|
||||
"NGN": true, //Naira
|
||||
"NIO": true, //Cordoba Oro
|
||||
"NOK": true, //Norwegian Krone
|
||||
"NPR": true, //Nepalese Rupee
|
||||
"NZD": true, //New Zealand Dollar
|
||||
"OMR": true, //Rial Omani
|
||||
"PAB": true, //Balboa
|
||||
"PEN": true, //Sol
|
||||
"PGK": true, //Kina
|
||||
"PHP": true, //Philippine Peso
|
||||
"PKR": true, //Pakistan Rupee
|
||||
"PLN": true, //Zloty
|
||||
"PYG": true, //Guarani
|
||||
"QAR": true, //Qatari Rial
|
||||
"RON": true, //Romanian Leu
|
||||
"RSD": true, //Serbian Dinar
|
||||
"RUB": true, //Russian Ruble
|
||||
"RWF": true, //Rwanda Franc
|
||||
"SAR": true, //Saudi Riyal
|
||||
"SBD": true, //Solomon Islands Dollar
|
||||
"SCR": true, //Seychelles Rupee
|
||||
"SDG": true, //Sudanese Pound
|
||||
"SEK": true, //Swedish Krona
|
||||
"SGD": true, //Singapore Dollar
|
||||
"SHP": true, //Saint Helena Pound
|
||||
"SLL": true, //Leone
|
||||
"SOS": true, //Somali Shilling
|
||||
"SRD": true, //Surinam Dollar
|
||||
"SSP": true, //South Sudanese Pound
|
||||
"STN": true, //Dobra
|
||||
"SVC": true, //El Salvador Colon
|
||||
"SYP": true, //Syrian Pound
|
||||
"SZL": true, //Lilangeni
|
||||
"THB": true, //Baht
|
||||
"TJS": true, //Somoni
|
||||
"TMT": true, //Turkmenistan New Manat
|
||||
"TND": true, //Tunisian Dinar
|
||||
"TOP": true, //Pa’anga
|
||||
"TRY": true, //Turkish Lira
|
||||
"TTD": true, //Trinidad and Tobago Dollar
|
||||
"TWD": true, //New Taiwan Dollar
|
||||
"TZS": true, //Tanzanian Shilling
|
||||
"UAH": true, //Hryvnia
|
||||
"UGX": true, //Uganda Shilling
|
||||
"USD": true, //US Dollar
|
||||
"UYU": true, //Peso Uruguayo
|
||||
"UZS": true, //Uzbekistan Sum
|
||||
"VES": true, //Bolívar Soberano
|
||||
"VND": true, //Dong
|
||||
"VUV": true, //Vatu
|
||||
"WST": true, //Tala
|
||||
"XAF": true, //CFA Franc BEAC
|
||||
"XCD": true, //East Caribbean Dollar
|
||||
"XOF": true, //CFA Franc BCEAO
|
||||
"XPF": true, //CFP Franc
|
||||
"YER": true, //Yemeni Rial
|
||||
"ZAR": true, //Rand
|
||||
"ZMW": true, //Zambian Kwacha
|
||||
"ZWL": true, //Zimbabwe Dollar
|
||||
}
|
||||
|
||||
func ValidCurrency(fl validator.FieldLevel) bool {
|
||||
if value, ok := fl.Field().Interface().(string); ok {
|
||||
_, ok := ALL_CURRENCY_NAMES[value]
|
||||
return ok
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user