add DeletePermissionMethod
This commit is contained in:
parent
7753de40ef
commit
e8547dfcda
|
@ -107,6 +107,15 @@ func (s Service) UpdatePermission(permissionID string, payload model.PermissionU
|
|||
return nil
|
||||
}
|
||||
|
||||
// DeletePermission ...
|
||||
func (s Service) DeletePermission(permissionID string) error {
|
||||
if err := permission.Delete(permissionID); err != nil {
|
||||
return err
|
||||
}
|
||||
cache.Roles()
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetAllPermissions ...
|
||||
func (s Service) GetAllPermissions(query model.PermissionAllQuery) model.PermissionAll {
|
||||
return permission.All(query)
|
||||
|
|
|
@ -54,6 +54,22 @@ func updateOneByCondition(ctx context.Context, cond interface{}, payload interfa
|
|||
return err
|
||||
}
|
||||
|
||||
func deleteOneByCondition(ctx context.Context, cond interface{}) error {
|
||||
var (
|
||||
col = database.GetPermissionCol()
|
||||
)
|
||||
_, err := col.DeleteOne(ctx, cond)
|
||||
if err != nil {
|
||||
logger.Error("usermngmt - Permission - DeleteOne", logger.LogData{
|
||||
"cond": cond,
|
||||
"err": err.Error(),
|
||||
})
|
||||
return fmt.Errorf("error when delete permission: %s", err.Error())
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func findByCondition(ctx context.Context, cond interface{}, opts ...*options.FindOptions) (docs []model.DBPermission) {
|
||||
var (
|
||||
col = database.GetPermissionCol()
|
||||
|
|
|
@ -94,6 +94,29 @@ func Update(permissionID string, payload model.PermissionUpdateOptions) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Delete ...
|
||||
func Delete(permissionID string) error {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
)
|
||||
|
||||
// Find permissionID exists or not
|
||||
id, isValid := mongodb.NewIDFromString(permissionID)
|
||||
if !isValid {
|
||||
return errors.New("invalid permission id data")
|
||||
}
|
||||
if !isPermissionIDExisted(ctx, id) {
|
||||
return errors.New("permission not found")
|
||||
}
|
||||
|
||||
// Delete
|
||||
if err := deleteOneByCondition(ctx, bson.M{"_id": id}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// All ...
|
||||
func All(queryParams model.PermissionAllQuery) (r model.PermissionAll) {
|
||||
var (
|
||||
|
|
Loading…
Reference in New Issue