feat: more-currency-support (#316)

* add polish and turkish lira

* add romanian lei

* code-gen
This commit is contained in:
Hayden 2023-02-25 18:13:52 -09:00 committed by GitHub
parent 729293745f
commit 70297b9d27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 14 deletions

View file

@ -101,8 +101,6 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/swaggo/files v1.0.0 h1:1gGXVIeUFCS/dta17rnP0iOpr6CXFwKD7EO5ID233e4=

View file

@ -133,6 +133,9 @@ const (
CurrencyRmb Currency = "rmb"
CurrencyBgn Currency = "bgn"
CurrencyChf Currency = "chf"
CurrencyPln Currency = "pln"
CurrencyTry Currency = "try"
CurrencyRon Currency = "ron"
)
func (c Currency) String() string {
@ -142,7 +145,7 @@ func (c Currency) String() string {
// CurrencyValidator is a validator for the "currency" field enum values. It is called by the builders before save.
func CurrencyValidator(c Currency) error {
switch c {
case CurrencyUsd, CurrencyEur, CurrencyGbp, CurrencyJpy, CurrencyZar, CurrencyAud, CurrencyNok, CurrencySek, CurrencyDkk, CurrencyInr, CurrencyRmb, CurrencyBgn, CurrencyChf:
case CurrencyUsd, CurrencyEur, CurrencyGbp, CurrencyJpy, CurrencyZar, CurrencyAud, CurrencyNok, CurrencySek, CurrencyDkk, CurrencyInr, CurrencyRmb, CurrencyBgn, CurrencyChf, CurrencyPln, CurrencyTry, CurrencyRon:
return nil
default:
return fmt.Errorf("group: invalid enum value for currency field: %q", c)

View file

@ -116,7 +116,7 @@ var (
{Name: "created_at", Type: field.TypeTime},
{Name: "updated_at", Type: field.TypeTime},
{Name: "name", Type: field.TypeString, Size: 255},
{Name: "currency", Type: field.TypeEnum, Enums: []string{"usd", "eur", "gbp", "jpy", "zar", "aud", "nok", "sek", "dkk", "inr", "rmb", "bgn", "chf"}, Default: "usd"},
{Name: "currency", Type: field.TypeEnum, Enums: []string{"usd", "eur", "gbp", "jpy", "zar", "aud", "nok", "sek", "dkk", "inr", "rmb", "bgn", "chf", "pln", "try", "ron"}, Default: "usd"},
}
// GroupsTable holds the schema information for the "groups" table.
GroupsTable = &schema.Table{

View file

@ -27,7 +27,7 @@ func (Group) Fields() []ent.Field {
NotEmpty(),
field.Enum("currency").
Default("usd").
Values("usd", "eur", "gbp", "jpy", "zar", "aud", "nok", "sek", "dkk", "inr", "rmb", "bgn","chf"),
Values("usd", "eur", "gbp", "jpy", "zar", "aud", "nok", "sek", "dkk", "inr", "rmb", "bgn", "chf", "pln", "try", "ron"),
}
}

View file

@ -1,17 +1,20 @@
export type Codes =
| "USD"
| "AUD"
| "BGN"
| "CHF"
| "DKK"
| "EUR"
| "GBP"
| "JPY"
| "ZAR"
| "AUD"
| "NOK"
| "SEK"
| "DKK"
| "INR"
| "JPY"
| "NOK"
| "PLN"
| "RMB"
| "BGN"
| "CHF";
| "RON"
| "SEK"
| "TRY"
| "USD"
| "ZAR";
export type Currency = {
code: Codes;
@ -69,6 +72,18 @@ export const currencies: Currency[] = [
symbol: "kr",
name: "Norwegian Krone",
},
{
code: "PLN",
local: "pl-PL",
symbol: "zł",
name: "Polish Zloty",
},
{
code: "RON",
local: "ro-RO",
symbol: "lei",
name: "Romanian Leu",
},
{
code: "ZAR",
local: "en-ZA",
@ -81,6 +96,12 @@ export const currencies: Currency[] = [
symbol: "kr",
name: "Swedish Krona",
},
{
code: "TRY",
local: "tr-TR",
symbol: "₺",
name: "Turkish Lira",
},
{
code: "USD",
local: "en-US",