Skip to content

Commit

Permalink
fix: dictionary does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Trevor-Lan committed Aug 27, 2022
1 parent 313bbbd commit 379a132
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"ark-admin-zero/app/core/cmd/api/internal/svc"
"ark-admin-zero/app/core/cmd/api/internal/types"
"ark-admin-zero/app/core/model"
"ark-admin-zero/common/config"
"ark-admin-zero/common/errorx"

"github.com/jinzhu/copier"
Expand All @@ -27,6 +28,12 @@ func NewAddConfigDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Add
}

func (l *AddConfigDictLogic) AddConfigDict(req *types.AddConfigDictReq) error {
if req.ParentId != config.SysTopParentId {
_, err := l.svcCtx.SysDictionaryModel.FindOne(l.ctx, req.ParentId)
if err != nil {
return errorx.NewDefaultError(errorx.ParentDictionaryIdErrorCode)
}
}
_, err := l.svcCtx.SysDictionaryModel.FindOneByUniqueKey(l.ctx, req.UniqueKey)
if err == model.ErrNotFound {
var dictionary = new(model.SysDictionary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"ark-admin-zero/app/core/cmd/api/internal/svc"
"ark-admin-zero/app/core/cmd/api/internal/types"
"ark-admin-zero/common/config"
"ark-admin-zero/common/errorx"

"github.com/jinzhu/copier"
Expand All @@ -26,6 +27,13 @@ func NewUpdateConfigDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
}

func (l *UpdateConfigDictLogic) UpdateConfigDict(req *types.UpdateConfigDictReq) error {
if req.ParentId != config.SysTopParentId {
_, err := l.svcCtx.SysDictionaryModel.FindOne(l.ctx, req.ParentId)
if err != nil {
return errorx.NewDefaultError(errorx.ParentDictionaryIdErrorCode)
}
}

configDictionary, err := l.svcCtx.SysDictionaryModel.FindOne(l.ctx, req.Id)
if err != nil {
return errorx.NewDefaultError(errorx.ServerErrorCode)
Expand Down
2 changes: 2 additions & 0 deletions common/errorx/errormsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
ParentRoleIdErrorCode = 1037
ParentDeptIdErrorCode = 1038
ParentPermMenuIdErrorCode = 1039
ParentDictionaryIdErrorCode = 1040
)

func init() {
Expand Down Expand Up @@ -86,6 +87,7 @@ func init() {
errorMsg[ParentRoleIdErrorCode] = "父级角色不存在"
errorMsg[ParentDeptIdErrorCode] = "父级部门不存在"
errorMsg[ParentPermMenuIdErrorCode] = "父级菜单不存在"
errorMsg[ParentDictionaryIdErrorCode] = "字典集不存在"
}

func MapErrMsg(errCode int) string {
Expand Down

0 comments on commit 379a132

Please sign in to comment.