working commit

This commit is contained in:
2026-02-21 12:31:39 +02:00
parent 3220e2d78f
commit cd37a4508c
37 changed files with 354 additions and 319 deletions
+20 -20
View File
@@ -6,8 +6,8 @@ import (
"mstore/pkg/auxpwd"
"mstore/pkg/auxtool"
"mstore/pkg/auxuuid"
"mstore/pkg/descr"
"mstore/pkg/auxid"
)
type CreateAccountParams struct {
@@ -15,10 +15,10 @@ type CreateAccountParams struct {
Password string `json:"password"`
}
type CreateAccountResult struct {
AccountID uint64 `json:"accountId"`
AccountID string `json:"accountId"`
}
func (oper *Operator) CreateAccount(ctx context.Context, operatorID uint64, params *CreateAccountParams) (*CreateAccountResult, error) {
func (oper *Operator) CreateAccount(ctx context.Context, operatorID string, params *CreateAccountParams) (*CreateAccountResult, error) {
var err error
res := &CreateAccountResult{}
@@ -43,7 +43,7 @@ func (oper *Operator) CreateAccount(ctx context.Context, operatorID uint64, para
now := auxtool.TimeNow()
passhash := auxpwd.MakeSHA256Hash([]byte(params.Password))
accountDescr := &descr.Account{
ID: auxid.NewID(),
ID: auxuuid.NewUUID(),
Username: params.Username,
Passhash: passhash,
Disabled: false,
@@ -62,18 +62,18 @@ func (oper *Operator) CreateAccount(ctx context.Context, operatorID uint64, para
// GetAccount
type GetAccountParams struct {
Username string `json:"username"`
AccountID uint64 `json:"accountId"`
Username string `json:"username"`
AccountID string `json:"accountId"`
}
type GetAccountResult struct {
Account *descr.AccountShort `json:"account"`
}
func (oper *Operator) GetAccount(ctx context.Context, operatorID uint64, params *GetAccountParams) (*GetAccountResult, error) {
func (oper *Operator) GetAccount(ctx context.Context, operatorID string, params *GetAccountParams) (*GetAccountResult, error) {
var err error
res := &GetAccountResult{}
if params.Username == "" && params.AccountID == 0 {
if params.Username == "" && params.AccountID == "" {
err := fmt.Errorf("Empty username and accountId parameter")
return res, err
}
@@ -81,7 +81,7 @@ func (oper *Operator) GetAccount(ctx context.Context, operatorID uint64, params
var accountDescr *descr.Account
var accountExists bool
switch {
case params.AccountID != 0:
case params.AccountID != "":
accountExists, accountDescr, err = oper.mdb.GetAccountByID(ctx, params.AccountID)
if err != nil {
return res, err
@@ -128,25 +128,25 @@ func (oper *Operator) GetAccount(ctx context.Context, operatorID uint64, params
}
type UpdateAccountParams struct {
Username string `json:"username"`
AccountID uint64 `json:"accountId"`
NewUsername string `json:"newUsername"`
NewPassword string `json:"newPassword"`
Disabled bool `json:"disabled"`
Username string `json:"username"`
AccountID string `json:"accountId"`
NewUsername string `json:"newUsername"`
NewPassword string `json:"newPassword"`
Disabled bool `json:"disabled"`
}
type UpdateAccountResult struct{}
func (oper *Operator) UpdateAccount(ctx context.Context, operatorID uint64, params *UpdateAccountParams) (*UpdateAccountResult, error) {
func (oper *Operator) UpdateAccount(ctx context.Context, operatorID string, params *UpdateAccountParams) (*UpdateAccountResult, error) {
var err error
res := &UpdateAccountResult{}
if params.Username == "" && params.AccountID == 0 {
if params.Username == "" && params.AccountID == "" {
err := fmt.Errorf("Empty username and accountId parameter")
return res, err
}
var accountDescr *descr.Account
var accountExists bool
switch {
case params.AccountID != 0:
case params.AccountID != "":
accountExists, accountDescr, err = oper.mdb.GetAccountByID(ctx, params.AccountID)
if err != nil {
return res, err
@@ -195,12 +195,12 @@ func (oper *Operator) UpdateAccount(ctx context.Context, operatorID uint64, para
}
type DeleteAccountParams struct {
Username string `json:"username"`
AccountID uint64 `json:"accountId"`
Username string `json:"username"`
AccountID string `json:"accountId"`
}
type DeleteAccountResult struct{}
func (oper *Operator) DeleteAccount(ctx context.Context, operatorID uint64, params *DeleteAccountParams) (*DeleteAccountResult, error) {
func (oper *Operator) DeleteAccount(ctx context.Context, operatorID string, params *DeleteAccountParams) (*DeleteAccountResult, error) {
var err error
res := &DeleteAccountResult{}