working commit
This commit is contained in:
@@ -22,6 +22,7 @@ type Account struct {
|
||||
}
|
||||
|
||||
type AccountShort struct {
|
||||
ID string `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Disabled bool `json:"disabled"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
package descr
|
||||
|
||||
const AnonymousID = "10000000-0000-0000-0000-000000000001"
|
||||
|
||||
type Grant struct {
|
||||
ID string `json:"id" db:"id"`
|
||||
AccountID string `json:"accountID" db:"account_id"`
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
//"fmt"
|
||||
|
||||
//"mstore/app/descr"
|
||||
"mstore/app/descr"
|
||||
"mstore/app/operator"
|
||||
"mstore/app/router"
|
||||
)
|
||||
@@ -12,13 +10,15 @@ import (
|
||||
func (hand *Handler) CreateAccount(rctx *router.Context) {
|
||||
var err error
|
||||
|
||||
operatorID := descr.AnonymousID
|
||||
|
||||
params := &operator.CreateAccountParams{}
|
||||
err = rctx.BindJSON(params)
|
||||
if err != nil {
|
||||
hand.SendError(rctx, err)
|
||||
return
|
||||
}
|
||||
res, err := hand.oper.CreateAccount(rctx.Ctx, params)
|
||||
res, err := hand.oper.CreateAccount(rctx.Ctx, operatorID, params)
|
||||
if err != nil {
|
||||
hand.logg.Errorf("CreateAccount error: %v", err)
|
||||
hand.SendError(rctx, err)
|
||||
|
||||
+10
-2
@@ -37,7 +37,7 @@ type CreateAccountResult struct {
|
||||
AccountID string `json:"accountId"`
|
||||
}
|
||||
|
||||
func (oper *Operator) CreateAccount(ctx context.Context, params *CreateAccountParams) (*CreateAccountResult, error) {
|
||||
func (oper *Operator) CreateAccount(ctx context.Context, operatorID string, params *CreateAccountParams) (*CreateAccountResult, error) {
|
||||
var err error
|
||||
res := &CreateAccountResult{}
|
||||
|
||||
@@ -68,6 +68,8 @@ func (oper *Operator) CreateAccount(ctx context.Context, params *CreateAccountPa
|
||||
Disabled: false,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
CreatedBy: operatorID,
|
||||
UpdatedBy: operatorID,
|
||||
}
|
||||
err = oper.mdb.InsertAccount(ctx, accountDescr)
|
||||
if err != nil {
|
||||
@@ -112,10 +114,13 @@ func (oper *Operator) GetAccount(ctx context.Context, params *GetAccountParams)
|
||||
}
|
||||
}
|
||||
accountShort := &descr.AccountShort{
|
||||
ID: accountDescr.ID,
|
||||
Username: accountDescr.Username,
|
||||
Disabled: accountDescr.Disabled,
|
||||
CreatedAt: accountDescr.CreatedAt,
|
||||
UpdatedAt: accountDescr.UpdatedAt,
|
||||
CreatedBy: accountDescr.CreatedBy,
|
||||
UpdatedBy: accountDescr.UpdatedBy,
|
||||
Disabled: accountDescr.Disabled,
|
||||
Grants: make([]descr.GrantShort, 0),
|
||||
}
|
||||
grantDescrs, err := oper.mdb.ListGrantsByAccountID(ctx, accountDescr.ID)
|
||||
@@ -252,10 +257,13 @@ func (oper *Operator) ListAccounts(ctx context.Context, params *ListAccountsPara
|
||||
}
|
||||
for _, accountDescr := range accountDescrs {
|
||||
accountShort := descr.AccountShort{
|
||||
ID: accountDescr.ID,
|
||||
Username: accountDescr.Username,
|
||||
Disabled: accountDescr.Disabled,
|
||||
CreatedAt: accountDescr.CreatedAt,
|
||||
UpdatedAt: accountDescr.UpdatedAt,
|
||||
CreatedBy: accountDescr.CreatedBy,
|
||||
UpdatedBy: accountDescr.UpdatedBy,
|
||||
Grants: make([]descr.GrantShort, 0),
|
||||
}
|
||||
grantDescrs, err := oper.mdb.ListGrantsByAccountID(ctx, accountDescr.ID)
|
||||
|
||||
Reference in New Issue
Block a user