working commit
This commit is contained in:
+37
-6
@@ -13,7 +13,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/app/handler"
|
||||
@@ -54,9 +53,9 @@ func (cli *Client) CreateAccount(ctx context.Context, hosturi, username, passwor
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (cli *Client) GetAccountByID(ctx context.Context, hosturi, id string) (descr.AccountShort, error) {
|
||||
func (cli *Client) GetAccountByID(ctx context.Context, hosturi, id string) (*descr.AccountShort, error) {
|
||||
var err error
|
||||
var res descr.AccountShort
|
||||
res := &descr.AccountShort{}
|
||||
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/account/get")
|
||||
if err != nil {
|
||||
@@ -84,13 +83,14 @@ func (cli *Client) GetAccountByID(ctx context.Context, hosturi, id string) (desc
|
||||
err = fmt.Errorf("%s", operRes.Message)
|
||||
return res, err
|
||||
}
|
||||
res = operRes.Result.Account
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (cli *Client) GetAccountByName(ctx context.Context, hosturi, username string) error {
|
||||
var err error
|
||||
|
||||
apipath, err := url.JoinPath(hosturi, "/v3/api/account/get")
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/account/get")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -121,7 +121,7 @@ func (cli *Client) GetAccountByName(ctx context.Context, hosturi, username strin
|
||||
func (cli *Client) UpdateAccount(ctx context.Context, hosturi, id, username, newUsername, newPassword string) error {
|
||||
var err error
|
||||
|
||||
apipath, err := url.JoinPath(hosturi, "/v3/api/account/update")
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/account/update")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -154,7 +154,7 @@ func (cli *Client) UpdateAccount(ctx context.Context, hosturi, id, username, new
|
||||
func (cli *Client) DeleteAccount(ctx context.Context, hosturi, id, username string) error {
|
||||
var err error
|
||||
|
||||
apipath, err := url.JoinPath(hosturi, "/v3/api/account/delete")
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/account/delete")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -182,3 +182,34 @@ func (cli *Client) DeleteAccount(ctx context.Context, hosturi, id, username stri
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (cli *Client) ListAccounts(ctx context.Context, hosturi string) ([]descr.AccountShort, error) {
|
||||
var err error
|
||||
res := make([]descr.AccountShort, 0)
|
||||
|
||||
apipath, err := setApiPath(hosturi, "/v3/api/accounts/list")
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
operParams := operator.ListAccountsParams{}
|
||||
paramsJson, err := json.Marshal(operParams)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
respBytes, err := doHTTPCall(ctx, apipath, paramsJson)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
operRes := handler.NewResponse[operator.ListAccountsResult]()
|
||||
err = json.Unmarshal(respBytes, operRes)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
if operRes.Error {
|
||||
err = fmt.Errorf("%s", operRes.Message)
|
||||
return res, err
|
||||
}
|
||||
res = operRes.Result.Accounts
|
||||
return res, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user