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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeletePermission ...
|
||||||
|
func (s Service) DeletePermission(permissionID string) error {
|
||||||
|
if err := permission.Delete(permissionID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cache.Roles()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetAllPermissions ...
|
// GetAllPermissions ...
|
||||||
func (s Service) GetAllPermissions(query model.PermissionAllQuery) model.PermissionAll {
|
func (s Service) GetAllPermissions(query model.PermissionAllQuery) model.PermissionAll {
|
||||||
return permission.All(query)
|
return permission.All(query)
|
||||||
|
|
|
@ -54,6 +54,22 @@ func updateOneByCondition(ctx context.Context, cond interface{}, payload interfa
|
||||||
return err
|
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) {
|
func findByCondition(ctx context.Context, cond interface{}, opts ...*options.FindOptions) (docs []model.DBPermission) {
|
||||||
var (
|
var (
|
||||||
col = database.GetPermissionCol()
|
col = database.GetPermissionCol()
|
||||||
|
|
|
@ -94,6 +94,29 @@ func Update(permissionID string, payload model.PermissionUpdateOptions) error {
|
||||||
return nil
|
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 ...
|
// All ...
|
||||||
func All(queryParams model.PermissionAllQuery) (r model.PermissionAll) {
|
func All(queryParams model.PermissionAllQuery) (r model.PermissionAll) {
|
||||||
var (
|
var (
|
||||||
|
|
Loading…
Reference in New Issue