You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
4.0 KiB

  1. package api
  2. import (
  3. "fmt"
  4. "gin-vue-admin/global/response"
  5. "gin-vue-admin/model"
  6. "github.com/gin-gonic/gin"
  7. )
  8. // @Tags {{.StructName}}
  9. // @Summary 创建{{.StructName}}
  10. // @Security ApiKeyAuth
  11. // @accept application/json
  12. // @Produce application/json
  13. // @Param data body model.{{.StructName}} true "创建{{.StructName}}"
  14. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  15. // @Router /{{.Abbreviation}}/create{{.StructName}} [post]
  16. func Create{{.StructName}}(c *gin.Context) {
  17. var {{.Abbreviation}} {{.PackageName}}.{{.StructName}}
  18. _ = c.ShouldBindJSON(&{{.Abbreviation}})
  19. err := {{.Abbreviation}}.Create{{.StructName}}()
  20. if err != nil {
  21. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("创建失败,%v", err), c)
  22. } else {
  23. response.Result(response.SUCCESS, gin.H{}, "创建成功", c)
  24. }
  25. }
  26. // @Tags {{.StructName}}
  27. // @Summary 删除{{.StructName}}
  28. // @Security ApiKeyAuth
  29. // @accept application/json
  30. // @Produce application/json
  31. // @Param data body model.{{.StructName}} true "删除{{.StructName}}"
  32. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  33. // @Router /{{.Abbreviation}}/delete{{.StructName}} [post]
  34. func Delete{{.StructName}}(c *gin.Context) {
  35. var {{.Abbreviation}} {{.PackageName}}.{{.StructName}}
  36. _ = c.ShouldBindJSON(&{{.Abbreviation}})
  37. err := {{.Abbreviation}}.Delete{{.StructName}}()
  38. if err != nil {
  39. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("删除失败,%v", err), c)
  40. } else {
  41. response.Result(response.SUCCESS, gin.H{}, "删除成功", c)
  42. }
  43. }
  44. // @Tags {{.StructName}}
  45. // @Summary 更新{{.StructName}}
  46. // @Security ApiKeyAuth
  47. // @accept application/json
  48. // @Produce application/json
  49. // @Param data body model.{{.StructName}} true "更新{{.StructName}}"
  50. // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
  51. // @Router /{{.Abbreviation}}/update{{.StructName}} [post]
  52. func Update{{.StructName}}(c *gin.Context) {
  53. var {{.Abbreviation}} {{.PackageName}}.{{.StructName}}
  54. _ = c.ShouldBindJSON(&{{.Abbreviation}})
  55. err,re{{.Abbreviation}} := {{.Abbreviation}}.Update{{.StructName}}()
  56. if err != nil {
  57. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("更新失败,%v", err), c)
  58. } else {
  59. response.Result(response.SUCCESS, gin.H{
  60. "re{{.Abbreviation}}":re{{.Abbreviation}},
  61. }, "更新成功", c)
  62. }
  63. }
  64. // @Tags {{.StructName}}
  65. // @Summary 用id查询{{.StructName}}
  66. // @Security ApiKeyAuth
  67. // @accept application/json
  68. // @Produce application/json
  69. // @Param data body model.{{.StructName}} true "用id查询{{.StructName}}"
  70. // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
  71. // @Router /{{.Abbreviation}}/find{{.StructName}} [post]
  72. func Find{{.StructName}}(c *gin.Context) {
  73. var {{.Abbreviation}} {{.PackageName}}.{{.StructName}}
  74. _ = c.ShouldBindJSON(&{{.Abbreviation}})
  75. err,re{{.Abbreviation}} := {{.Abbreviation}}.FindById()
  76. if err != nil {
  77. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("查询失败,%v", err), c)
  78. } else {
  79. response.Result(response.SUCCESS, gin.H{
  80. "re{{.Abbreviation}}":re{{.Abbreviation}},
  81. }, "查询成功", c)
  82. }
  83. }
  84. // @Tags {{.StructName}}
  85. // @Summary 分页获取{{.StructName}}列表
  86. // @Security ApiKeyAuth
  87. // @accept application/json
  88. // @Produce application/json
  89. // @Param data body model.PageInfo true "分页获取{{.StructName}}列表"
  90. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  91. // @Router /{{.Abbreviation}}/get{{.StructName}}List [post]
  92. func Get{{.StructName}}List(c *gin.Context) {
  93. var pageInfo model.PageInfo
  94. _ = c.ShouldBindJSON(&pageInfo)
  95. err, list, total := new({{.PackageName}}.{{.StructName}}).GetInfoList(pageInfo)
  96. if err != nil {
  97. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("获取数据失败,%v", err), c)
  98. } else {
  99. response.Result(response.SUCCESS, gin.H{
  100. "{{.PackageName}}List": list,
  101. "total": total,
  102. "page": pageInfo.Page,
  103. "pageSize": pageInfo.PageSize,
  104. }, "获取数据成功", c)
  105. }
  106. }