api层写法统一

This commit is contained in:
linwenxiang committed 2021-03-12 16:02:29 +08:00
1 parent fa30b8db95
commit 9bf9330410
40 files changed
+430 -316

No files matched your search

+6 -6
View File
@@ -2,6 +2,7 @@ package actions
import (
"errors"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"net/http"
"github.com/gin-gonic/gin"
@@ -9,7 +10,6 @@ import (
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"gorm.io/gorm"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/common/dto"
"go-admin/common/models"
)
@@ -28,13 +28,13 @@ func ViewAction(control dto.Control, f func() interface{}) gin.HandlerFunc {
req := control.Generate()
err = req.Bind(c)
if err != nil {
app.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
response.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
return
}
var object models.ActiveRecord
object, err = req.GenerateM()
if err != nil {
app.Error(c, http.StatusInternalServerError, err, "模型生成失败")
response.Error(c, http.StatusInternalServerError, err, "模型生成失败")
return
}
@@ -53,15 +53,15 @@ func ViewAction(control dto.Control, f func() interface{}) gin.HandlerFunc {
).Where(req.GetId()).First(rsp).Error
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
app.Error(c, http.StatusNotFound, nil, "查看对象不存在或无权查看")
response.Error(c, http.StatusNotFound, nil, "查看对象不存在或无权查看")
return
}
if err != nil {
log.Errorf("MsgID[%s] View error: %s", msgID, err)
app.Error(c, http.StatusInternalServerError, err, "查看失败")
response.Error(c, http.StatusInternalServerError, err, "查看失败")
return
}
app.OK(c, rsp, "查看成功")
response.OK(c, rsp, "查看成功")
c.Next()
}
}