From 379a132d2879e056b48c3efb68bfd0da53ae34e6 Mon Sep 17 00:00:00 2001
From: Trevor-Lan
Date: Sat, 27 Aug 2022 08:04:57 +0800
Subject: [PATCH] fix: dictionary does not exist
---
.../api/internal/logic/config/dict/addconfigdictlogic.go | 7 +++++++
.../internal/logic/config/dict/updateconfigdictlogic.go | 8 ++++++++
common/errorx/errormsg.go | 2 ++
3 files changed, 17 insertions(+)
diff --git a/app/core/cmd/api/internal/logic/config/dict/addconfigdictlogic.go b/app/core/cmd/api/internal/logic/config/dict/addconfigdictlogic.go
index 86a2a06..107dc4d 100644
--- a/app/core/cmd/api/internal/logic/config/dict/addconfigdictlogic.go
+++ b/app/core/cmd/api/internal/logic/config/dict/addconfigdictlogic.go
@@ -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"
@@ -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)
diff --git a/app/core/cmd/api/internal/logic/config/dict/updateconfigdictlogic.go b/app/core/cmd/api/internal/logic/config/dict/updateconfigdictlogic.go
index 7778a2f..f5eeb9b 100644
--- a/app/core/cmd/api/internal/logic/config/dict/updateconfigdictlogic.go
+++ b/app/core/cmd/api/internal/logic/config/dict/updateconfigdictlogic.go
@@ -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"
@@ -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)
diff --git a/common/errorx/errormsg.go b/common/errorx/errormsg.go
index 5c933b4..5ffc2f5 100644
--- a/common/errorx/errormsg.go
+++ b/common/errorx/errormsg.go
@@ -43,6 +43,7 @@ const (
ParentRoleIdErrorCode = 1037
ParentDeptIdErrorCode = 1038
ParentPermMenuIdErrorCode = 1039
+ ParentDictionaryIdErrorCode = 1040
)
func init() {
@@ -86,6 +87,7 @@ func init() {
errorMsg[ParentRoleIdErrorCode] = "父级角色ä¸å˜åœ¨"
errorMsg[ParentDeptIdErrorCode] = "父级部门ä¸å˜åœ¨"
errorMsg[ParentPermMenuIdErrorCode] = "父级èœå•ä¸å˜åœ¨"
+ errorMsg[ParentDictionaryIdErrorCode] = "å—典集ä¸å˜åœ¨"
}
func MapErrMsg(errCode int) string {