|
| 1 | +package api |
| 2 | + |
| 3 | +import ( |
| 4 | + "strconv" |
| 5 | + "github.com/gin-gonic/gin" |
| 6 | + "{{.ModName}}/util/global" |
| 7 | + "{{.ModName}}/util/result" |
| 8 | + "{{.ModName}}/{{.Abbr}}/model" |
| 9 | + "{{.ModName}}/{{.Abbr}}/service" |
| 10 | +) |
| 11 | + |
| 12 | +// @Tags {{.SupStructName}} |
| 13 | +// @Summary 创建{{.SupStructName}} |
| 14 | +// @accept application/json |
| 15 | +// @Produce application/json |
| 16 | +// @Param data body model.{{.SupStructName}} true "创建{{.SupStructName}}" |
| 17 | +// @Success 200 {string} string "{"code":200,"data":{},"msg":"操作成功"}" |
| 18 | +// @Router /{{.RouterName}}/create{{.SupStructName}} [post] |
| 19 | +func Create{{.SupStructName}}(c *gin.Context) { |
| 20 | +
|
| 21 | + var req model.{{.SupStructName}} |
| 22 | + |
| 23 | + if err := c.ShouldBindJSON(&req);err != nil { |
| 24 | + c.JSON(200, result.ReturnFailMsg("获取参数失败")) |
| 25 | + } else { |
| 26 | + res := service.Create{{.SupStructName}}(req) |
| 27 | + c.JSON(200, res) |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +// @Tags {{.SupStructName}} |
| 32 | +// @Summary 删除{{.SupStructName}} |
| 33 | +// @accept application/json |
| 34 | +// @Produce application/json |
| 35 | +// @Param data body model.{{.SupStructName}} true "删除{{.SupStructName}}" |
| 36 | +// @Success 200 {string} string "{"code":200,"data":{},"msg":"删除成功"}" |
| 37 | +// @Router /{{.RouterName}}/delete{{.SupStructName}} [delete] |
| 38 | +func Delete{{.SupStructName}}(c *gin.Context) { |
| 39 | +
|
| 40 | + var req model.{{.SupStructName}} |
| 41 | + |
| 42 | + if err := c.ShouldBindJSON(&req);err != nil { |
| 43 | + c.JSON(200, result.ReturnFailMsg("获取参数失败")) |
| 44 | + } else { |
| 45 | + res := service.Delete{{.SupStructName}}(req) |
| 46 | + c.JSON(200, res) |
| 47 | + } |
| 48 | + |
| 49 | +} |
| 50 | + |
| 51 | +// @Tags {{.SupStructName}} |
| 52 | +// @Summary 批量删除{{.SupStructName}} |
| 53 | +// @accept application/json |
| 54 | +// @Produce application/json |
| 55 | +// @Param data body global.IdsReq true "批量删除{{.SupStructName}}" |
| 56 | +// @Success 200 {string} string "{"code":200,"data":{},"msg":"删除成功"}" |
| 57 | +// @Router /{{.RouterName}}/delete{{.SupStructName}}ByIds [delete] |
| 58 | +func Delete{{.SupStructName}}ByIds(c *gin.Context) { |
| 59 | +
|
| 60 | + var req global.IdsReq |
| 61 | +
|
| 62 | + if err := c.ShouldBindJSON(&req);err != nil { |
| 63 | + c.JSON(200, result.ReturnFailMsg("获取参数失败")) |
| 64 | + } else { |
| 65 | + res := service.Delete{{.SupStructName}}ByIds(req.Ids) |
| 66 | + c.JSON(200, res) |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +// @Tags {{.SupStructName}} |
| 71 | +// @Summary 更新{{.SupStructName}} |
| 72 | +// @accept application/json |
| 73 | +// @Produce application/json |
| 74 | +// @Param data body model.{{.SupStructName}} true "更新{{.SupStructName}}" |
| 75 | +// @Success 200 {string} string "{"code":200,"data":{},"msg":"更新成功"}" |
| 76 | +// @Router /{{.RouterName}}/update{{.SupStructName}} [put] |
| 77 | +func Update{{.SupStructName}}(c *gin.Context) { |
| 78 | + var req model.{{.SupStructName}} |
| 79 | + |
| 80 | + if err := c.ShouldBindJSON(&req);err != nil { |
| 81 | + c.JSON(200, result.ReturnFailMsg("获取参数失败")) |
| 82 | + } else { |
| 83 | + res := service.Update{{.SupStructName}}(req) |
| 84 | + c.JSON(200, res) |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +// @Tags {{.SupStructName}} |
| 89 | +// @Summary 用id查询{{.SupStructName}} |
| 90 | +// @accept application/json |
| 91 | +// @Produce application/json |
| 92 | +// @Param id path integer true "ID" |
| 93 | +// @Success 200 {string} string "{"code":200,"data":{},"msg":"查询成功"}" |
| 94 | +// @Router /{{.RouterName}}/get/{id} [get] |
| 95 | +func Get{{.SupStructName}}(c *gin.Context) { |
| 96 | +
|
| 97 | + idstr:=c.Param("id") //查询路径Path参数 |
| 98 | + id, err := strconv.ParseInt(idstr, 10, 64) |
| 99 | + if err!=nil{ |
| 100 | + c.JSON(200, result.ReturnFailMsg("获取参数失败")) |
| 101 | + }else{ |
| 102 | + res := service.Get{{.SupStructName}}(id) |
| 103 | + c.JSON(200, res) |
| 104 | + } |
| 105 | + |
| 106 | +} |
| 107 | + |
| 108 | +// @Tags {{.SupStructName}} |
| 109 | +// @Summary 分页获取{{.SupStructName}}列表 |
| 110 | +// @accept application/json |
| 111 | +// @Produce application/json |
| 112 | +// @Param data body model.{{.SupStructName}}Req true "分页获取{{.SupStructName}}列表" |
| 113 | +// @Success 200 {string} string "{"code":200,"data":{},"msg":"获取成功"}" |
| 114 | +// @Router /{{.RouterName}}/get{{.SupStructName}}List [post] |
| 115 | +func GetPageLimit{{.SupStructName}}(c *gin.Context) { |
| 116 | +
|
| 117 | + var req model.{{.SupStructName}}Req |
| 118 | + |
| 119 | + if err := c.ShouldBindJSON(&req);err != nil { |
| 120 | + c.JSON(200, result.ReturnFailMsg("获取参数失败")) |
| 121 | + } else { |
| 122 | + res := service.GetPageLimit{{.SupStructName}}(req) |
| 123 | + c.JSON(200, res) |
| 124 | + } |
| 125 | +} |
0 commit comments