working commit
This commit is contained in:
+14
-14
@@ -7,7 +7,7 @@ import (
|
||||
"mstore/pkg/auxpwd"
|
||||
"mstore/pkg/auxtool"
|
||||
"mstore/pkg/descr"
|
||||
"mstore/pkg/uuid"
|
||||
"mstore/pkg/auxid"
|
||||
)
|
||||
|
||||
type CreateAccountParams struct {
|
||||
@@ -15,10 +15,10 @@ type CreateAccountParams struct {
|
||||
Password string `json:"password"`
|
||||
}
|
||||
type CreateAccountResult struct {
|
||||
AccountID uuid.UUID `json:"accountId"`
|
||||
AccountID uint64 `json:"accountId"`
|
||||
}
|
||||
|
||||
func (oper *Operator) CreateAccount(ctx context.Context, operatorID uuid.UUID, params *CreateAccountParams) (*CreateAccountResult, error) {
|
||||
func (oper *Operator) CreateAccount(ctx context.Context, operatorID uint64, params *CreateAccountParams) (*CreateAccountResult, error) {
|
||||
var err error
|
||||
res := &CreateAccountResult{}
|
||||
|
||||
@@ -43,7 +43,7 @@ func (oper *Operator) CreateAccount(ctx context.Context, operatorID uuid.UUID, p
|
||||
now := auxtool.TimeNow()
|
||||
passhash := auxpwd.MakeSHA256Hash([]byte(params.Password))
|
||||
accountDescr := &descr.Account{
|
||||
ID: uuid.NewUUID(),
|
||||
ID: auxid.NewID(),
|
||||
Username: params.Username,
|
||||
Passhash: passhash,
|
||||
Disabled: false,
|
||||
@@ -63,17 +63,17 @@ func (oper *Operator) CreateAccount(ctx context.Context, operatorID uuid.UUID, p
|
||||
// GetAccount
|
||||
type GetAccountParams struct {
|
||||
Username string `json:"username"`
|
||||
AccountID uuid.UUID `json:"accountId"`
|
||||
AccountID uint64 `json:"accountId"`
|
||||
}
|
||||
type GetAccountResult struct {
|
||||
Account *descr.AccountShort `json:"account"`
|
||||
}
|
||||
|
||||
func (oper *Operator) GetAccount(ctx context.Context, operatorID uuid.UUID, params *GetAccountParams) (*GetAccountResult, error) {
|
||||
func (oper *Operator) GetAccount(ctx context.Context, operatorID uint64, params *GetAccountParams) (*GetAccountResult, error) {
|
||||
var err error
|
||||
res := &GetAccountResult{}
|
||||
|
||||
if params.Username == "" && params.AccountID == "" {
|
||||
if params.Username == "" && params.AccountID == 0 {
|
||||
err := fmt.Errorf("Empty username and accountId parameter")
|
||||
return res, err
|
||||
}
|
||||
@@ -81,7 +81,7 @@ func (oper *Operator) GetAccount(ctx context.Context, operatorID uuid.UUID, para
|
||||
var accountDescr *descr.Account
|
||||
var accountExists bool
|
||||
switch {
|
||||
case params.AccountID != "":
|
||||
case params.AccountID != 0:
|
||||
accountExists, accountDescr, err = oper.mdb.GetAccountByID(ctx, params.AccountID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
@@ -129,24 +129,24 @@ func (oper *Operator) GetAccount(ctx context.Context, operatorID uuid.UUID, para
|
||||
|
||||
type UpdateAccountParams struct {
|
||||
Username string `json:"username"`
|
||||
AccountID uuid.UUID `json:"accountId"`
|
||||
AccountID uint64 `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 uuid.UUID, params *UpdateAccountParams) (*UpdateAccountResult, error) {
|
||||
func (oper *Operator) UpdateAccount(ctx context.Context, operatorID uint64, params *UpdateAccountParams) (*UpdateAccountResult, error) {
|
||||
var err error
|
||||
res := &UpdateAccountResult{}
|
||||
if params.Username == "" && params.AccountID == "" {
|
||||
if params.Username == "" && params.AccountID == 0 {
|
||||
err := fmt.Errorf("Empty username and accountId parameter")
|
||||
return res, err
|
||||
}
|
||||
var accountDescr *descr.Account
|
||||
var accountExists bool
|
||||
switch {
|
||||
case params.AccountID != "":
|
||||
case params.AccountID != 0:
|
||||
accountExists, accountDescr, err = oper.mdb.GetAccountByID(ctx, params.AccountID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
@@ -196,11 +196,11 @@ func (oper *Operator) UpdateAccount(ctx context.Context, operatorID uuid.UUID, p
|
||||
|
||||
type DeleteAccountParams struct {
|
||||
Username string `json:"username"`
|
||||
AccountID uuid.UUID `json:"accountId"`
|
||||
AccountID uint64 `json:"accountId"`
|
||||
}
|
||||
type DeleteAccountResult struct{}
|
||||
|
||||
func (oper *Operator) DeleteAccount(ctx context.Context, operatorID uuid.UUID, params *DeleteAccountParams) (*DeleteAccountResult, error) {
|
||||
func (oper *Operator) DeleteAccount(ctx context.Context, operatorID uint64, params *DeleteAccountParams) (*DeleteAccountResult, error) {
|
||||
var err error
|
||||
res := &DeleteAccountResult{}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user