Skip to content

Commit b4ad609

Browse files
Merge pull request #38 from simonbronner/bugfix/reduce-payload-size-update-user-accounts
Provide just the account id(s) in the payload sent to the /admin/user/account endpoint - significant reduction in payload size
2 parents 7dcd8d1 + b735379 commit b4ad609

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

client/user.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,18 @@ func (client *Client) DeleteUserFromAccount(accountId, userId string) error {
278278
return nil
279279
}
280280

281+
func ToSlimAccount(account Account) Account {
282+
return Account{ID: account.ID}
283+
}
284+
285+
func ToSlimAccounts(accounts []Account) []Account {
286+
var result []Account
287+
for i := 0; i < len(accounts); i++ {
288+
result = append(result, ToSlimAccount(accounts[i]))
289+
}
290+
return result
291+
}
292+
281293
func (client *Client) UpdateUserAccounts(userId string, accounts []Account) error {
282294

283295
// API call '/accounts/{accountId}/{userId}/adduser' doesn't work
@@ -287,9 +299,11 @@ func (client *Client) UpdateUserAccounts(userId string, accounts []Account) erro
287299
return err
288300
}
289301

302+
var _accounts = ToSlimAccounts(accounts)
303+
290304
postUser := UserAccounts{
291305
UserName: user.UserName,
292-
Account: accounts,
306+
Account: _accounts,
293307
}
294308

295309
body, err := EncodeToJSON(postUser)

0 commit comments

Comments
 (0)