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.

115 lines
3.9 KiB

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