From a373c33bc6d7432ec886999ebc57298d033f665b Mon Sep 17 00:00:00 2001 From: weizhihong Date: Wed, 30 Aug 2023 14:26:48 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=97=A0=E6=9D=83=E9=99=90=E6=8B=A6?= =?UTF-8?q?=E6=88=AA=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dto/error.go | 2 ++ middleware/auth.go | 3 +-- service/publishedGi.go | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/dto/error.go b/dto/error.go index 907c478..7931a83 100644 --- a/dto/error.go +++ b/dto/error.go @@ -12,4 +12,6 @@ const ( // DataOperationError 数据操作错误(增删改查操作出了意料之外的错误都算) DataOperationError = 2002 ArgumentParseError = 3000 + + NoAuthOperationError = 4001 ) diff --git a/middleware/auth.go b/middleware/auth.go index 27352a3..0da5a40 100644 --- a/middleware/auth.go +++ b/middleware/auth.go @@ -1,7 +1,6 @@ package middleware import ( - "net/http" "strings" "github.com/gin-gonic/gin" @@ -39,7 +38,7 @@ func permissionMiddleware() gin.HandlerFunc { if isVaild { // 用户有权限 c.Next() } else { - c.JSON(http.StatusUnauthorized, "无权限访问") + panic(dto.ErrorDto{Code: dto.NoAuthOperationError, Message: "无权限操作"}) } } } diff --git a/service/publishedGi.go b/service/publishedGi.go index bdd330c..ba1e2be 100644 --- a/service/publishedGi.go +++ b/service/publishedGi.go @@ -57,7 +57,7 @@ func PublishFormDraft(req *publishedGi.PublishReqDto, user *model.User) { } //需要删除的同名数据 oldData, _ := dbquery.PublishedGi.Debug().Where(dbquery.PublishedGi.Name.Eq(req.Name)).Find() - if oldData != nil && len(oldData) > 0 { + if len(oldData) > 0 { // 逻辑删除 dbquery.PublishedGi.Debug().Where(dbquery.PublishedGi.Name.Eq(req.Name)).UpdateColumn(dbquery.PublishedGi.Status, 0) for _, v := range oldData {