maxapi: add currency field to the accounts api

This commit is contained in:
c9s 2023-05-04 17:20:42 +08:00
parent 40f6295d91
commit 1ca81e11e6
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 20 additions and 6 deletions

View File

@ -6,13 +6,14 @@ import "github.com/c9s/requestgen"
//go:generate -command PostRequest requestgen -method POST
//go:generate -command DeleteRequest requestgen -method DELETE
func (s *Client) NewGetWalletAccountsRequest(walletType WalletType) *GetWalletAccountsRequest {
return &GetWalletAccountsRequest{client: s.Client, walletType: walletType}
}
//go:generate GetRequest -url "/api/v3/wallet/:walletType/accounts" -type GetWalletAccountsRequest -responseType []Account
type GetWalletAccountsRequest struct {
client requestgen.AuthenticatedAPIClient
walletType WalletType `param:"walletType,slug,required"`
currency string `param:"currency"`
}
func (s *Client) NewGetWalletAccountsRequest(walletType WalletType) *GetWalletAccountsRequest {
return &GetWalletAccountsRequest{client: s.Client, walletType: walletType}
}

View File

@ -12,6 +12,11 @@ import (
"regexp"
)
func (g *GetWalletAccountsRequest) Currency(currency string) *GetWalletAccountsRequest {
g.currency = currency
return g
}
func (g *GetWalletAccountsRequest) WalletType(walletType max.WalletType) *GetWalletAccountsRequest {
g.walletType = walletType
return g
@ -32,6 +37,11 @@ func (g *GetWalletAccountsRequest) GetQueryParameters() (url.Values, error) {
// GetParameters builds and checks the parameters and return the result in a map object
func (g *GetWalletAccountsRequest) GetParameters() (map[string]interface{}, error) {
var params = map[string]interface{}{}
// check currency field -> json key currency
currency := g.currency
// assign parameter of currency
params["currency"] = currency
return params, nil
}
@ -128,9 +138,12 @@ func (g *GetWalletAccountsRequest) GetSlugsMap() (map[string]string, error) {
func (g *GetWalletAccountsRequest) Do(ctx context.Context) ([]max.Account, error) {
// no body params
// empty params for GET operation
var params interface{}
query := url.Values{}
query, err := g.GetParametersQuery()
if err != nil {
return nil, err
}
apiURL := "/api/v3/wallet/:walletType/accounts"
slugs, err := g.GetSlugsMap()