mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 01:34:24 +08:00
verify whether currency code is in known list
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/mayswind/lab/pkg/errs"
|
"github.com/mayswind/lab/pkg/errs"
|
||||||
"github.com/mayswind/lab/pkg/log"
|
"github.com/mayswind/lab/pkg/log"
|
||||||
"github.com/mayswind/lab/pkg/models"
|
"github.com/mayswind/lab/pkg/models"
|
||||||
|
"github.com/mayswind/lab/pkg/validators"
|
||||||
)
|
)
|
||||||
|
|
||||||
const euroCentralBankExchangeRateUrl = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"
|
const euroCentralBankExchangeRateUrl = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"
|
||||||
@@ -59,6 +60,11 @@ func (e *EuroCentralBankExchangeRateData) ToLatestExchangeRateResponse(c *core.C
|
|||||||
|
|
||||||
for i := 0; i < len(latestEuroCentralBankExchangeRate.ExchangeRates); i++ {
|
for i := 0; i < len(latestEuroCentralBankExchangeRate.ExchangeRates); i++ {
|
||||||
exchangeRate := latestEuroCentralBankExchangeRate.ExchangeRates[i]
|
exchangeRate := latestEuroCentralBankExchangeRate.ExchangeRates[i]
|
||||||
|
|
||||||
|
if _, exists := validators.AllCurrencyNames[exchangeRate.Currency]; !exists {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
exchangeRates = append(exchangeRates, exchangeRate.ToLatestExchangeRate())
|
exchangeRates = append(exchangeRates, exchangeRate.ToLatestExchangeRate())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
const ParentAccountCurrencyPlaceholder = "---"
|
const ParentAccountCurrencyPlaceholder = "---"
|
||||||
|
|
||||||
// ISO 4217
|
// ISO 4217
|
||||||
var allCurrencyNames = map[string]bool{
|
var AllCurrencyNames = map[string]bool{
|
||||||
"AED": true, //UAE Dirham
|
"AED": true, //UAE Dirham
|
||||||
"AFN": true, //Afghani
|
"AFN": true, //Afghani
|
||||||
"ALL": true, //Lek
|
"ALL": true, //Lek
|
||||||
@@ -175,7 +175,7 @@ func ValidCurrency(fl validator.FieldLevel) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
_, ok := allCurrencyNames[value]
|
_, ok := AllCurrencyNames[value]
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user