Skip to content

Commit

Permalink
Merge pull request #23 from rarimo/fix/countries-config
Browse files Browse the repository at this point in the history
Replace country map to country array
  • Loading branch information
Zaptoss authored Jun 11, 2024
2 parents 0634d5e + b26015b commit 5f88367
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions docs/spec/components/schemas/CountriesConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ allOf:
- countries
properties:
countries:
type: object
type: array
description: |
Map from country codes to their properties.
Array of codes and their properties.
Each code is ISO 3166-1 alpha-3 code (3-letter uppercase).
additionalProperties:
items:
$ref: '#/components/schemas/CountryProperties'
4 changes: 4 additions & 0 deletions docs/spec/components/schemas/CountryProperties.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
type: object
required:
- code
- reserve_allowed
- withdrawal_allowed
properties:
code:
type: string
description: ISO 3166-1 alpha-3 country code
reserve_allowed:
type: boolean
description: Whether the users of country are allowed to reserve (claim) tokens
Expand Down
7 changes: 4 additions & 3 deletions internal/service/handlers/countries_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ func GetCountriesConfig(w http.ResponseWriter, r *http.Request) {
return
}

cMap := make(map[string]resources.CountryProperties)
properties := make([]resources.CountryProperties, 0, len(countries))
for _, c := range countries {
prop := resources.CountryProperties{
Code: c.Code,
ReserveAllowed: c.ReserveAllowed,
WithdrawalAllowed: c.WithdrawalAllowed,
}
// when the limit is reached, reserve is not allowed despite the config
if c.Reserved >= c.ReserveLimit {
prop.ReserveAllowed = false
}
cMap[c.Code] = prop
properties = append(properties, prop)
}

ape.Render(w, resources.CountriesConfigResponse{
Expand All @@ -35,7 +36,7 @@ func GetCountriesConfig(w http.ResponseWriter, r *http.Request) {
Type: resources.COUNTRIES_CONFIG,
},
Attributes: resources.CountriesConfigAttributes{
Countries: cMap,
Countries: properties,
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion resources/model_countries_config_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ package resources

type CountriesConfigAttributes struct {
// Map from country codes to their properties. Each code is ISO 3166-1 alpha-3 code (3-letter uppercase).
Countries map[string]CountryProperties `json:"countries"`
Countries []CountryProperties `json:"countries"`
}
2 changes: 2 additions & 0 deletions resources/model_country_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package resources

type CountryProperties struct {
// ISO 3166-1 alpha-3 country code
Code string `json:"code"`
// Whether the users of country are allowed to reserve (claim) tokens
ReserveAllowed bool `json:"reserve_allowed"`
// Whether the users of country are allowed to withdraw tokens
Expand Down

0 comments on commit 5f88367

Please sign in to comment.