41 lines
789 B
Go
41 lines
789 B
Go
package accoper
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"mstore/pkg/descr"
|
|
)
|
|
|
|
// Get Grants
|
|
type GetGrantParams struct {
|
|
GrantID string `json:"grantId"`
|
|
}
|
|
type GetGrantResult struct {
|
|
Grant *descr.Grant `json:"grant"`
|
|
}
|
|
|
|
func (oper *Operator) GetGrant(ctx context.Context, operatorID string, params *GetGrantParams) (*GetGrantResult, error) {
|
|
var err error
|
|
res := &GetGrantResult{}
|
|
|
|
if params.GrantID == "" {
|
|
err := fmt.Errorf("Empty grantId parameter")
|
|
return res, err
|
|
}
|
|
|
|
var grantDescr *descr.Grant
|
|
var grantExists bool
|
|
grantExists, grantDescr, err = oper.mdb.GetGrantByID(ctx, params.GrantID)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
if !grantExists {
|
|
err := fmt.Errorf("Grant with ID %s dont exists", params.GrantID)
|
|
return res, err
|
|
}
|
|
|
|
res.Grant = grantDescr
|
|
return res, err
|
|
}
|