working commit
This commit is contained in:
+26
-14
@@ -100,15 +100,19 @@ func (oper *Operator) UpdateAccount(ctx context.Context, params *UpdateAccountPa
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
if !accountExists {
|
||||
err := fmt.Errorf("Account with ID %s dont exists", params.AccountID)
|
||||
return res, err
|
||||
}
|
||||
case params.Username != "":
|
||||
accountExists, accountDescr, err = oper.mdb.GetAccountByUsername(ctx, params.Username)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
}
|
||||
if !accountExists {
|
||||
err := fmt.Errorf("Account with this is or name dont exists")
|
||||
return res, err
|
||||
if !accountExists {
|
||||
err := fmt.Errorf("Account with name %s dont exists", params.Username)
|
||||
return res, err
|
||||
}
|
||||
}
|
||||
now := auxtool.TimeNow()
|
||||
if params.NewUsername != "" {
|
||||
@@ -150,15 +154,19 @@ func (oper *Operator) DeleteAccount(ctx context.Context, params *DeleteAccountPa
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
if !accountExists {
|
||||
err := fmt.Errorf("Account with ID %s dont exists", params.AccountID)
|
||||
return res, err
|
||||
}
|
||||
case params.Username != "":
|
||||
accountExists, accountDescr, err = oper.mdb.GetAccountByUsername(ctx, params.Username)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
}
|
||||
if !accountExists {
|
||||
err := fmt.Errorf("Account with this is or name dont exists")
|
||||
return res, err
|
||||
if !accountExists {
|
||||
err := fmt.Errorf("Account with name %s dont exists", params.Username)
|
||||
return res, err
|
||||
}
|
||||
}
|
||||
|
||||
err = oper.mdb.DeleteAllGrantsForAccountID(ctx, accountDescr.ID)
|
||||
@@ -216,7 +224,7 @@ type GetAccountParams struct {
|
||||
AccountID string
|
||||
}
|
||||
type GetAccountResult struct {
|
||||
Account *descr.AccountShortDescr `json:"accountDescr"`
|
||||
Account *descr.AccountShortDescr `json:"account"`
|
||||
}
|
||||
|
||||
func (oper *Operator) GetAccount(ctx context.Context, params *GetAccountParams) (*GetAccountResult, error) {
|
||||
@@ -227,19 +235,23 @@ func (oper *Operator) GetAccount(ctx context.Context, params *GetAccountParams)
|
||||
var accountExists bool
|
||||
switch {
|
||||
case params.AccountID != "":
|
||||
accountExists, accountDescr, err = oper.mdb.GetAccountByID(ctx, params.Username)
|
||||
accountExists, accountDescr, err = oper.mdb.GetAccountByID(ctx, params.AccountID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
if !accountExists {
|
||||
err := fmt.Errorf("Account with ID %s dont exists", params.AccountID)
|
||||
return res, err
|
||||
}
|
||||
case params.Username != "":
|
||||
accountExists, accountDescr, err = oper.mdb.GetAccountByUsername(ctx, params.Username)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
}
|
||||
if !accountExists {
|
||||
err := fmt.Errorf("Account with this is or name dont exists")
|
||||
return res, err
|
||||
if !accountExists {
|
||||
err := fmt.Errorf("Account with name %s dont exists", params.Username)
|
||||
return res, err
|
||||
}
|
||||
}
|
||||
accountShortDescr := &descr.AccountShortDescr{
|
||||
Username: accountDescr.Username,
|
||||
|
||||
+16
-12
@@ -23,16 +23,18 @@ import (
|
||||
"mstore/pkg/auxuuid"
|
||||
)
|
||||
|
||||
// FileExists
|
||||
type FileExistsParams struct {
|
||||
// FileInfo
|
||||
type FileInfoParams struct {
|
||||
Filepath string
|
||||
Source string
|
||||
Dest string
|
||||
}
|
||||
type FileExistsResult struct {
|
||||
ContentType string
|
||||
ContentSize string
|
||||
ContentDigest string
|
||||
type FileInfoResult struct {
|
||||
ContentCollection string
|
||||
ContentName string
|
||||
ContentType string
|
||||
ContentSize string
|
||||
ContentDigest string
|
||||
}
|
||||
|
||||
func cleanFilepath(filename string) (string, error) {
|
||||
@@ -40,10 +42,10 @@ func cleanFilepath(filename string) (string, error) {
|
||||
return filepath.Clean(filename), nil
|
||||
}
|
||||
|
||||
func (oper *Operator) FileExists(ctx context.Context, param *FileExistsParams) (int, *FileExistsResult, error) {
|
||||
func (oper *Operator) FileInfo(ctx context.Context, param *FileInfoParams) (int, *FileInfoResult, error) {
|
||||
var err error
|
||||
code := http.StatusOK
|
||||
res := &FileExistsResult{}
|
||||
res := &FileInfoResult{}
|
||||
|
||||
xfilepath, err := cleanFilepath(param.Filepath)
|
||||
if err != nil {
|
||||
@@ -63,10 +65,12 @@ func (oper *Operator) FileExists(ctx context.Context, param *FileExistsParams) (
|
||||
code = http.StatusNotFound
|
||||
return code, res, err
|
||||
}
|
||||
res = &FileExistsResult{
|
||||
ContentSize: strconv.FormatInt(fileDescr.Size, 10),
|
||||
ContentType: fileDescr.Type,
|
||||
ContentDigest: fileDescr.Checksum,
|
||||
res = &FileInfoResult{
|
||||
ContentCollection: fileDescr.Collection,
|
||||
ContentName: fileDescr.Name,
|
||||
ContentSize: strconv.FormatInt(fileDescr.Size, 10),
|
||||
ContentType: fileDescr.Type,
|
||||
ContentDigest: fileDescr.Checksum,
|
||||
}
|
||||
return code, res, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user