From b73537916de9c5db2a7802251a3188e4985ea849 Mon Sep 17 00:00:00 2001 From: Simon Bronner Date: Sat, 13 Mar 2021 23:34:01 +1100 Subject: [PATCH] Provide just the account id(s) in the payload sent to the /admin/user/account endpoint - significant reduction in payload size --- client/user.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/client/user.go b/client/user.go index c9e32e6..0c29c15 100644 --- a/client/user.go +++ b/client/user.go @@ -278,6 +278,18 @@ func (client *Client) DeleteUserFromAccount(accountId, userId string) error { return nil } +func ToSlimAccount(account Account) Account { + return Account{ID: account.ID} +} + +func ToSlimAccounts(accounts []Account) []Account { + var result []Account + for i := 0; i < len(accounts); i++ { + result = append(result, ToSlimAccount(accounts[i])) + } + return result +} + func (client *Client) UpdateUserAccounts(userId string, accounts []Account) error { // API call '/accounts/{accountId}/{userId}/adduser' doesn't work @@ -287,9 +299,11 @@ func (client *Client) UpdateUserAccounts(userId string, accounts []Account) erro return err } + var _accounts = ToSlimAccounts(accounts) + postUser := UserAccounts{ UserName: user.UserName, - Account: accounts, + Account: _accounts, } body, err := EncodeToJSON(postUser)