v1.1
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
package admin_role_api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"context"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
"ycc-server/app/main/model"
|
||||
"ycc-server/common/xerr"
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
"ycc-server/app/main/model"
|
||||
"ycc-server/common/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type AdminUpdateRoleApiLogic struct {
|
||||
@@ -28,9 +29,9 @@ func NewAdminUpdateRoleApiLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||
|
||||
func (l *AdminUpdateRoleApiLogic) AdminUpdateRoleApi(req *types.AdminUpdateRoleApiReq) (resp *types.AdminUpdateRoleApiResp, err error) {
|
||||
// 1. 参数验证
|
||||
if req.RoleId <= 0 {
|
||||
if req.RoleId == "" {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.PARAM_VERIFICATION_ERROR),
|
||||
"角色ID必须大于0, roleId: %d", req.RoleId)
|
||||
"角色ID不能为空, roleId: %s", req.RoleId)
|
||||
}
|
||||
|
||||
// 2. 查询角色是否存在
|
||||
@@ -38,10 +39,10 @@ func (l *AdminUpdateRoleApiLogic) AdminUpdateRoleApi(req *types.AdminUpdateRoleA
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR),
|
||||
"角色不存在, roleId: %d", req.RoleId)
|
||||
"角色不存在, roleId: %s", req.RoleId)
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR),
|
||||
"查询角色失败, err: %v, roleId: %d", err, req.RoleId)
|
||||
"查询角色失败, err: %v, roleId: %s", err, req.RoleId)
|
||||
}
|
||||
|
||||
// 3. 删除该角色的所有API权限
|
||||
@@ -63,7 +64,7 @@ func (l *AdminUpdateRoleApiLogic) AdminUpdateRoleApi(req *types.AdminUpdateRoleA
|
||||
// 4. 添加新的API权限
|
||||
if len(req.ApiIds) > 0 {
|
||||
for _, apiId := range req.ApiIds {
|
||||
if apiId <= 0 {
|
||||
if apiId == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -71,18 +72,19 @@ func (l *AdminUpdateRoleApiLogic) AdminUpdateRoleApi(req *types.AdminUpdateRoleA
|
||||
_, err := l.svcCtx.AdminApiModel.FindOne(l.ctx, apiId)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
logx.Errorf("API不存在, apiId: %d", apiId)
|
||||
logx.Errorf("API不存在, apiId: %s", apiId)
|
||||
continue
|
||||
}
|
||||
logx.Errorf("查询API失败, err: %v, apiId: %d", err, apiId)
|
||||
logx.Errorf("查询API失败, err: %v, apiId: %s", err, apiId)
|
||||
continue
|
||||
}
|
||||
|
||||
// 创建新的关联
|
||||
roleApiData := &model.AdminRoleApi{
|
||||
RoleId: req.RoleId,
|
||||
ApiId: apiId,
|
||||
}
|
||||
roleApiData := &model.AdminRoleApi{
|
||||
Id: uuid.NewString(),
|
||||
RoleId: req.RoleId,
|
||||
ApiId: apiId,
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.AdminRoleApiModel.Insert(l.ctx, nil, roleApiData)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user