From 990b48146f59baf1e5a6abc1392aca4678ffa768 Mon Sep 17 00:00:00 2001 From: luziqi Date: Tue, 25 Jul 2023 14:03:53 +0800 Subject: [PATCH] =?UTF-8?q?changed:=20=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- device/devices.go | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/device/devices.go b/device/devices.go index dc23a26..c5feabf 100644 --- a/device/devices.go +++ b/device/devices.go @@ -23,8 +23,7 @@ func GetDeviceByUdid(c *gin.Context) { udid := c.DefaultQuery("udid", "") if udid == "" { - rsp.Error("udid error") - c.JSON(http.StatusOK, rsp) + c.JSON(http.StatusOK, rsp.Error("udid error")) return } db, err := dbsql.GetConn(dbsql.DSN) @@ -39,8 +38,7 @@ func GetDeviceByUdid(c *gin.Context) { db.Model(&models.Device{}).Where("udid = ?", udid).Last(&device) if device.ID < 1 { - rsp.Error("没有找到该设备,udid-" + udid) - c.JSON(http.StatusOK, rsp) + c.JSON(http.StatusOK, rsp.Error("没有找到该设备,udid-"+udid)) return } @@ -120,8 +118,8 @@ func CreateDevice(c *gin.Context) { db, err := dbsql.GetConn(dbsql.DSN) if err != nil { - rsp.Error(err.Error()) - c.JSON(http.StatusOK, rsp) + c.JSON(http.StatusOK, rsp.Error(err.Error())) + return } defer dbsql.Close(db) @@ -146,15 +144,14 @@ func CreateDevice(c *gin.Context) { var _device models.Device db.Model(models.Device{}).Where("udid = ?", obj.Udid).Find(&_device) if _device.ID > 0 { - rsp.Error("添加失败,该设备已存在") - c.JSON(http.StatusOK, rsp) + c.JSON(http.StatusOK, rsp.Error("添加失败,该设备已存在")) return } db.Model(models.Device{}).Create(&obj) if db.Error != nil { - rsp.Error(db.Error.Error()) - c.JSON(http.StatusOK, rsp) + c.JSON(http.StatusOK, rsp.Error(db.Error.Error())) + return } rsp.Success() @@ -180,22 +177,21 @@ func UpdateDevice(c *gin.Context) { id := cast.ToInt(c.PostForm("id")) if id == 0 { - rsp.Error("device.id error - " + c.PostForm("id")) - c.JSON(http.StatusOK, rsp) + c.JSON(http.StatusOK, rsp.Error("device.id error - "+c.PostForm("id"))) + return } db, err := dbsql.GetConn(dbsql.DSN) if err != nil { - rsp.Error(err.Error()) - c.JSON(http.StatusOK, rsp) + c.JSON(http.StatusOK, rsp.Error(err.Error())) + return } defer dbsql.Close(db) var obj models.Device db.Model(models.Device{}).Where("id = ?", obj.ID).Find(&obj) if obj.ID < 1 { - rsp.Error("修改失败,该设备不存在") - c.JSON(http.StatusOK, rsp) + c.JSON(http.StatusOK, rsp.Error("修改失败,该设备不存在")) return } if c.PostForm("project") != "" { @@ -219,8 +215,8 @@ func UpdateDevice(c *gin.Context) { db.Model(models.Device{}).Where("id = ?", obj.ID).Updates(&obj) if db.Error != nil { - rsp.Error(db.Error.Error()) - c.JSON(http.StatusOK, rsp) + c.JSON(http.StatusOK, rsp.Error(db.Error.Error())) + return } rsp.Success()