working commit

This commit is contained in:
2026-02-12 14:51:16 +02:00
parent a9526f73a2
commit e4d9a6d161
7 changed files with 281 additions and 93 deletions
+50 -15
View File
@@ -15,16 +15,18 @@ import (
"fmt"
"net/url"
"mstore/app/descr"
"mstore/app/handler"
"mstore/app/operator"
)
func (cli *Client) CreateAccount(ctx context.Context, hosturi, username, password string) error {
func (cli *Client) CreateAccount(ctx context.Context, hosturi, username, password string) (string, error) {
var err error
var res string
apiuri, err := url.JoinPath(hosturi, "/v3/api/account/create")
apiuri, err := setApiPath(hosturi, "/v3/api/account/create")
if err != nil {
return err
return res, err
}
operParams := operator.CreateAccountParams{
Username: username,
@@ -32,26 +34,60 @@ func (cli *Client) CreateAccount(ctx context.Context, hosturi, username, passwor
}
paramsJson, err := json.Marshal(operParams)
if err != nil {
return err
return res, err
}
respBytes, err := doHTTPCall(ctx, apiuri, paramsJson)
if err != nil {
return err
return res, err
}
operRes := handler.NewResponse[operator.CreateAccountResult]()
err = json.Unmarshal(respBytes, operRes)
if err != nil {
return err
return res, err
}
if !operRes.Error {
if operRes.Error {
err = fmt.Errorf("%s", operRes.Message)
return err
return res, err
}
return err
res = operRes.Result.AccountID
return res, err
}
func (cli *Client) GetAccount(ctx context.Context, hosturi, id, username string) error {
func (cli *Client) GetAccountByID(ctx context.Context, hosturi, id string) (descr.AccountShort, error) {
var err error
var res descr.AccountShort
apipath, err := setApiPath(hosturi, "/v3/api/account/get")
if err != nil {
return res, err
}
operParams := operator.GetAccountParams{
AccountID: id,
}
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.GetAccountResult]()
err = json.Unmarshal(respBytes, operRes)
if err != nil {
return res, err
}
if operRes.Error {
err = fmt.Errorf("%s", operRes.Message)
return res, err
}
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")
@@ -59,8 +95,7 @@ func (cli *Client) GetAccount(ctx context.Context, hosturi, id, username string)
return err
}
operParams := operator.GetAccountParams{
Username: username,
AccountID: id,
Username: username,
}
paramsJson, err := json.Marshal(operParams)
if err != nil {
@@ -76,7 +111,7 @@ func (cli *Client) GetAccount(ctx context.Context, hosturi, id, username string)
if err != nil {
return err
}
if !operRes.Error {
if operRes.Error {
err = fmt.Errorf("%s", operRes.Message)
return err
}
@@ -109,7 +144,7 @@ func (cli *Client) UpdateAccount(ctx context.Context, hosturi, id, username, new
if err != nil {
return err
}
if !operRes.Error {
if operRes.Error {
err = fmt.Errorf("%s", operRes.Message)
return err
}
@@ -141,7 +176,7 @@ func (cli *Client) DeleteAccount(ctx context.Context, hosturi, id, username stri
if err != nil {
return err
}
if !operRes.Error {
if operRes.Error {
err = fmt.Errorf("%s", operRes.Message)
return err
}