123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- package v1
- import (
- "fmt"
- "gin-vue-admin/global/response"
- "gin-vue-admin/model"
- "gin-vue-admin/model/request"
- resp "gin-vue-admin/model/response"
- "gin-vue-admin/service"
- "github.com/gin-gonic/gin"
- )
- // @Tags {{.StructName}}
- // @Summary 创建{{.StructName}}
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body model.{{.StructName}} true "创建{{.StructName}}"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
- // @Router /{{.Abbreviation}}/create{{.StructName}} [post]
- func Create{{.StructName}}(c *gin.Context) {
- var {{.Abbreviation}} model.{{.StructName}}
- _ = c.ShouldBindJSON(&{{.Abbreviation}})
- err := service.Create{{.StructName}}({{.Abbreviation}})
- if err != nil {
- response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
- } else {
- response.OkWithMessage("创建成功", c)
- }
- }
- // @Tags {{.StructName}}
- // @Summary 删除{{.StructName}}
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body model.{{.StructName}} true "删除{{.StructName}}"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
- // @Router /{{.Abbreviation}}/delete{{.StructName}} [delete]
- func Delete{{.StructName}}(c *gin.Context) {
- var {{.Abbreviation}} model.{{.StructName}}
- _ = c.ShouldBindJSON(&{{.Abbreviation}})
- err := service.Delete{{.StructName}}({{.Abbreviation}})
- if err != nil {
- response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
- } else {
- response.OkWithMessage("删除成功", c)
- }
- }
- // @Tags {{.StructName}}
- // @Summary 批量删除{{.StructName}}
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body request.IdsReq true "批量删除{{.StructName}}"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
- // @Router /{{.Abbreviation}}/delete{{.StructName}}ByIds [delete]
- func Delete{{.StructName}}ByIds(c *gin.Context) {
- var IDS request.IdsReq
- _ = c.ShouldBindJSON(&IDS)
- err := service.Delete{{.StructName}}ByIds(IDS)
- if err != nil {
- response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
- } else {
- response.OkWithMessage("删除成功", c)
- }
- }
- // @Tags {{.StructName}}
- // @Summary 更新{{.StructName}}
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body model.{{.StructName}} true "更新{{.StructName}}"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
- // @Router /{{.Abbreviation}}/update{{.StructName}} [put]
- func Update{{.StructName}}(c *gin.Context) {
- var {{.Abbreviation}} model.{{.StructName}}
- _ = c.ShouldBindJSON(&{{.Abbreviation}})
- err := service.Update{{.StructName}}(&{{.Abbreviation}})
- if err != nil {
- response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
- } else {
- response.OkWithMessage("更新成功", c)
- }
- }
- // @Tags {{.StructName}}
- // @Summary 用id查询{{.StructName}}
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body model.{{.StructName}} true "用id查询{{.StructName}}"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
- // @Router /{{.Abbreviation}}/find{{.StructName}} [get]
- func Find{{.StructName}}(c *gin.Context) {
- var {{.Abbreviation}} model.{{.StructName}}
- _ = c.ShouldBindQuery(&{{.Abbreviation}})
- err, re{{.Abbreviation}} := service.Get{{.StructName}}({{.Abbreviation}}.ID)
- if err != nil {
- response.FailWithMessage(fmt.Sprintf("查询失败,%v", err), c)
- } else {
- response.OkWithData(gin.H{"re{{.Abbreviation}}": re{{.Abbreviation}}}, c)
- }
- }
- // @Tags {{.StructName}}
- // @Summary 分页获取{{.StructName}}列表
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body request.{{.StructName}}Search true "分页获取{{.StructName}}列表"
- // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
- // @Router /{{.Abbreviation}}/get{{.StructName}}List [get]
- func Get{{.StructName}}List(c *gin.Context) {
- var pageInfo request.{{.StructName}}Search
- _ = c.ShouldBindQuery(&pageInfo)
- err, list, total := service.Get{{.StructName}}InfoList(pageInfo)
- if err != nil {
- response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
- } else {
- response.OkWithData(resp.PageResult{
- List: list,
- Total: total,
- Page: pageInfo.Page,
- PageSize: pageInfo.PageSize,
- }, c)
- }
- }
|