先发布,后测试

This commit is contained in:
wyh 2023-12-29 13:24:21 +08:00
parent b2d53e0692
commit 78cc0d848e
1 changed files with 131 additions and 3 deletions

View File

@ -13,19 +13,19 @@ func SuperAdd(c *gin.Context) {
// c.Request.Body // c.Request.Body
b, err := io.ReadAll(c.Request.Body) b, err := io.ReadAll(c.Request.Body)
if err != nil { if err != nil {
c.JSON(401, gin.H{ c.JSON(402, gin.H{
"err": err.Error(), "err": err.Error(),
}) })
} }
if err := json.Unmarshal(b, &req); err != nil { if err := json.Unmarshal(b, &req); err != nil {
c.JSON(401, gin.H{ c.JSON(402, gin.H{
"err": err.Error(), "err": err.Error(),
}) })
} }
str, err := json.Marshal(req) str, err := json.Marshal(req)
if err != nil { if err != nil {
c.JSON(401, gin.H{ c.JSON(402, gin.H{
"err": err.Error(), "err": err.Error(),
}) })
} }
@ -39,3 +39,131 @@ func SuperAdd(c *gin.Context) {
"Res": *res, "Res": *res,
}) })
} }
func SuperList(c *gin.Context) {
var req = &struct {
Row int `form:"row"`
Index int `form:"index"`
}{}
if err := c.ShouldBindQuery(req); err != nil {
c.JSON(402, gin.H{
"err": err.Error(),
})
}
if req.Index == 0 {
req.Index = 1
}
if req.Row == 0 {
req.Row = 10
}
res, err := service.SuperList(req.Index, req.Row)
if err != nil {
c.JSON(500, gin.H{
"err": err.Error(),
})
}
c.JSON(200, res)
}
func SuperDetail(c *gin.Context) {
var req = &struct {
ID uint `form:"id"`
}{}
if err := c.ShouldBindQuery(req); err != nil {
c.JSON(402, gin.H{
"err": err.Error(),
})
}
if req.ID == 0 {
c.JSON(402, gin.H{
"err": "id不能为空",
})
return
}
res, err := service.SuperDetail(req.ID)
if err != nil {
c.JSON(500, gin.H{
"err": err.Error(),
})
}
c.JSON(200, res)
}
func SuperDetele(c *gin.Context) {
var req = &struct {
ID uint
}{}
if err := c.ShouldBind(req); err != nil {
c.JSON(402, gin.H{
"err": err.Error(),
})
}
if req.ID == 0 {
c.JSON(402, gin.H{
"err": "id不能为空",
})
return
}
res, err := service.SuperDetele(req.ID)
if err != nil {
c.JSON(500, gin.H{
"err": err.Error(),
})
}
c.JSON(200, res)
}
func SuperSave(c *gin.Context) {
var req1 = &struct {
ID uint
}{}
if err := c.ShouldBind(req1); err != nil {
c.JSON(402, gin.H{
"err": err.Error(),
})
}
if req1.ID == 0 {
c.JSON(402, gin.H{
"err": "id不能为空",
})
return
}
var req map[string]interface{}
// c.Request.Body
b, err := io.ReadAll(c.Request.Body)
if err != nil {
c.JSON(402, gin.H{
"err": err.Error(),
})
}
if err := json.Unmarshal(b, &req); err != nil {
c.JSON(402, gin.H{
"err": err.Error(),
})
}
str, err := json.Marshal(req)
if err != nil {
c.JSON(402, gin.H{
"err": err.Error(),
})
}
res, err := service.SuperSave(req1.ID, str)
if err != nil {
c.JSON(500, gin.H{
"err": err.Error(),
})
}
c.JSON(200, gin.H{
"Res": res,
})
}