working commit

This commit is contained in:
2026-02-14 11:36:02 +02:00
parent 801606b956
commit 7790b70372
2 changed files with 113 additions and 17 deletions
+40 -7
View File
@@ -87,35 +87,37 @@ func (cli *Client) GetAccountByID(ctx context.Context, hosturi, id string) (*des
return res, err
}
func (cli *Client) GetAccountByName(ctx context.Context, hosturi, username string) error {
func (cli *Client) GetAccountByName(ctx context.Context, hosturi, username string) (*descr.AccountShort, error) {
var err error
res := &descr.AccountShort{}
apipath, err := setApiPath(hosturi, "/v3/api/account/get")
if err != nil {
return err
return res, err
}
operParams := operator.GetAccountParams{
Username: username,
}
paramsJson, err := json.Marshal(operParams)
if err != nil {
return err
return res, err
}
respBytes, err := doHTTPCall(ctx, apipath, paramsJson)
if err != nil {
return err
return res, err
}
operRes := handler.NewResponse[operator.GetAccountResult]()
err = json.Unmarshal(respBytes, operRes)
if err != nil {
return err
return res, err
}
if operRes.Error {
err = fmt.Errorf("%s", operRes.Message)
return err
return res, err
}
return err
res = operRes.Result.Account
return res, err
}
func (cli *Client) UpdateAccountByID(ctx context.Context, hosturi, id, newUsername, newPassword string) error {
@@ -151,6 +153,37 @@ func (cli *Client) UpdateAccountByID(ctx context.Context, hosturi, id, newUserna
return err
}
func (cli *Client) UpdateAccountByName(ctx context.Context, hosturi, username, newUsername, newPassword string) error {
var err error
apipath, err := setApiPath(hosturi, "/v3/api/account/update")
if err != nil {
return err
}
operParams := operator.UpdateAccountParams{
Username: username,
NewUsername: newUsername,
NewPassword: newPassword,
}
paramsJson, err := json.Marshal(operParams)
if err != nil {
return err
}
respBytes, err := doHTTPCall(ctx, apipath, paramsJson)
if err != nil {
return err
}
operRes := handler.NewResponse[operator.UpdateAccountResult]()
err = json.Unmarshal(respBytes, operRes)
if err != nil {
return err
}
if operRes.Error {
err = fmt.Errorf("%s", operRes.Message)
return err
}
return err
}
func (cli *Client) DeleteAccountByName(ctx context.Context, hosturi, username string) error {
var err error