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.

117 lines
4.0 KiB

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