瀏覽代碼

tmr: validate upgrade

Yi 1 年之前
父節點
當前提交
3bba77df42
共有 3 個文件被更改,包括 18 次插入17 次删除
  1. 2 2
      go.mod
  2. 4 4
      go.sum
  3. 12 11
      http/handle/group/feed_formula.go

+ 2 - 2
go.mod

@@ -4,7 +4,7 @@ go 1.17
 
 require (
 	gitee.com/xuyiping_admin/go_proto v0.0.0-20230814081651-e5b0cb4c72c8
-	gitee.com/xuyiping_admin/pkg v0.0.0-20230802061948-5b07cd8c16e6
+	gitee.com/xuyiping_admin/pkg v0.0.0-20230816061144-c1f079802584
 	github.com/360EntSecGroup-Skylar/excelize v1.4.1
 	github.com/Anderson-Lu/gofasion v0.0.0-20190530065914-6a05b679ee48
 	github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible
@@ -17,7 +17,7 @@ require (
 	github.com/eclipse/paho.mqtt.golang v1.4.2
 	github.com/fastwego/offiaccount v1.0.1
 	github.com/gin-contrib/gzip v0.0.6
-	github.com/gin-gonic/gin v1.9.1
+	github.com/gin-gonic/gin v1.9.0
 	github.com/go-ini/ini v1.67.0
 	github.com/go-sql-driver/mysql v1.7.1
 	github.com/hequan2017/go-admin v1.4.0

+ 4 - 4
go.sum

@@ -5,8 +5,8 @@ gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGq
 gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20230814081651-e5b0cb4c72c8 h1:p6Y97HJ0VYAU+hOWBeOFM7k8UUMi+PmPAkmkVoyg+Uk=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20230814081651-e5b0cb4c72c8/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
-gitee.com/xuyiping_admin/pkg v0.0.0-20230802061948-5b07cd8c16e6 h1:K4RrKDO1SG1NOCoqNO0jnlGKmY7AfOmuqzDIw94KCTk=
-gitee.com/xuyiping_admin/pkg v0.0.0-20230802061948-5b07cd8c16e6/go.mod h1:h3kdB9CyxmW6duxLLA6fJezVCHa0g5+erAQ60iv+S58=
+gitee.com/xuyiping_admin/pkg v0.0.0-20230816061144-c1f079802584 h1:5RE5yrMMvnDITrnoX821mFl7dNYfsFA1osDobUV/TDo=
+gitee.com/xuyiping_admin/pkg v0.0.0-20230816061144-c1f079802584/go.mod h1:VQ7WztVDQRlXE1dUu/Yqo3ZdhKsfv7IGJtV+vqNqJVw=
 github.com/360EntSecGroup-Skylar/excelize v1.4.1 h1:l55mJb6rkkaUzOpSsgEeKYtS6/0gHwBYyfo5Jcjv/Ks=
 github.com/360EntSecGroup-Skylar/excelize v1.4.1/go.mod h1:vnax29X2usfl7HHkBrX5EvSCJcmH3dT9luvxzu8iGAE=
 github.com/Anderson-Lu/gofasion v0.0.0-20190530065914-6a05b679ee48 h1:Y0um3nHCQDleEpQzahJAkT8mvKTlLqvjoIqZYIAJgAw=
@@ -138,8 +138,8 @@ github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm
 github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y=
 github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM=
 github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk=
-github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
-github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
+github.com/gin-gonic/gin v1.9.0 h1:OjyFBKICoexlu99ctXNR2gg+c5pKrKMuyjgARg9qeY8=
+github.com/gin-gonic/gin v1.9.0/go.mod h1:W1Me9+hsUSyj3CePGrd1/QrKJMSJ1Tu/0hFEH89961k=
 github.com/glendc/gopher-json v0.0.0-20170414221815-dc4743023d0c/go.mod h1:Gja1A+xZ9BoviGJNA2E9vFkPjjsl+CoJxSXiQM1UXtw=
 github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
 github.com/go-ini/ini v1.44.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=

+ 12 - 11
http/handle/group/feed_formula.go

@@ -8,6 +8,10 @@ import (
 	"tmr-watch/pkg/e"
 	"tmr-watch/service/group"
 
+	"gitee.com/xuyiping_admin/pkg/valid"
+
+	"gitee.com/xuyiping_admin/pkg/apierr"
+
 	"github.com/gin-gonic/gin"
 )
 
@@ -22,29 +26,26 @@ func Handle404(c *gin.Context) {
 
 // DistributeFeedFormula 饲料配方下发
 func DistributeFeedFormula(c *gin.Context) {
-	appG := app.Gin{C: c}
 	var req models.PastureBodyRequest
 	if err := c.BindJSON(&req); err != nil {
-		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return
 	}
 
-	if len(req.FeedFormula) <= 0 {
-		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
-		return
-	}
-
-	if len(req.FeedFormulaDetail) <= 0 {
-		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+	if err := valid.ValidateStruct(&req,
+		valid.Field(&req.FeedFormula, valid.Required),
+		valid.Field(&req.FeedFormulaDetail, valid.Required),
+	); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return
 	}
 
 	if err := group.DistributeFeedFormulaService(&req); err != nil {
-		appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
+		apierr.ClassifiedAbort(c, err)
 		return
 	}
 
-	appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
+	c.JSON(http.StatusOK, map[string]bool{
 		"success": true,
 	})
 }