info.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. package api
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
  5. "github.com/flipped-aurora/gin-vue-admin/server/plugin/announcement/model"
  6. "github.com/flipped-aurora/gin-vue-admin/server/plugin/announcement/model/request"
  7. "github.com/gin-gonic/gin"
  8. "go.uber.org/zap"
  9. )
  10. var Info = new(info)
  11. type info struct{}
  12. // CreateInfo 创建公告
  13. // @Tags Info
  14. // @Summary 创建公告
  15. // @Security ApiKeyAuth
  16. // @accept application/json
  17. // @Produce application/json
  18. // @Param data body model.Info true "创建公告"
  19. // @Success 200 {object} response.Response{msg=string} "创建成功"
  20. // @Router /info/createInfo [post]
  21. func (a *info) CreateInfo(c *gin.Context) {
  22. var info model.Info
  23. err := c.ShouldBindJSON(&info)
  24. if err != nil {
  25. response.FailWithMessage(err.Error(), c)
  26. return
  27. }
  28. err = serviceInfo.CreateInfo(&info)
  29. if err != nil {
  30. global.GVA_LOG.Error("创建失败!", zap.Error(err))
  31. response.FailWithMessage("创建失败", c)
  32. return
  33. }
  34. response.OkWithMessage("创建成功", c)
  35. }
  36. // DeleteInfo 删除公告
  37. // @Tags Info
  38. // @Summary 删除公告
  39. // @Security ApiKeyAuth
  40. // @accept application/json
  41. // @Produce application/json
  42. // @Param data body model.Info true "删除公告"
  43. // @Success 200 {object} response.Response{msg=string} "删除成功"
  44. // @Router /info/deleteInfo [delete]
  45. func (a *info) DeleteInfo(c *gin.Context) {
  46. ID := c.Query("ID")
  47. err := serviceInfo.DeleteInfo(ID)
  48. if err != nil {
  49. global.GVA_LOG.Error("删除失败!", zap.Error(err))
  50. response.FailWithMessage("删除失败", c)
  51. return
  52. }
  53. response.OkWithMessage("删除成功", c)
  54. }
  55. // DeleteInfoByIds 批量删除公告
  56. // @Tags Info
  57. // @Summary 批量删除公告
  58. // @Security ApiKeyAuth
  59. // @accept application/json
  60. // @Produce application/json
  61. // @Success 200 {object} response.Response{msg=string} "批量删除成功"
  62. // @Router /info/deleteInfoByIds [delete]
  63. func (a *info) DeleteInfoByIds(c *gin.Context) {
  64. IDs := c.QueryArray("IDs[]")
  65. if err := serviceInfo.DeleteInfoByIds(IDs); err != nil {
  66. global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
  67. response.FailWithMessage("批量删除失败", c)
  68. return
  69. }
  70. response.OkWithMessage("批量删除成功", c)
  71. }
  72. // UpdateInfo 更新公告
  73. // @Tags Info
  74. // @Summary 更新公告
  75. // @Security ApiKeyAuth
  76. // @accept application/json
  77. // @Produce application/json
  78. // @Param data body model.Info true "更新公告"
  79. // @Success 200 {object} response.Response{msg=string} "更新成功"
  80. // @Router /info/updateInfo [put]
  81. func (a *info) UpdateInfo(c *gin.Context) {
  82. var info model.Info
  83. err := c.ShouldBindJSON(&info)
  84. if err != nil {
  85. response.FailWithMessage(err.Error(), c)
  86. return
  87. }
  88. err = serviceInfo.UpdateInfo(info)
  89. if err != nil {
  90. global.GVA_LOG.Error("更新失败!", zap.Error(err))
  91. response.FailWithMessage("更新失败", c)
  92. return
  93. }
  94. response.OkWithMessage("更新成功", c)
  95. }
  96. // FindInfo 用id查询公告
  97. // @Tags Info
  98. // @Summary 用id查询公告
  99. // @Security ApiKeyAuth
  100. // @accept application/json
  101. // @Produce application/json
  102. // @Param data query model.Info true "用id查询公告"
  103. // @Success 200 {object} response.Response{data=model.Info,msg=string} "查询成功"
  104. // @Router /info/findInfo [get]
  105. func (a *info) FindInfo(c *gin.Context) {
  106. ID := c.Query("ID")
  107. reinfo, err := serviceInfo.GetInfo(ID)
  108. if err != nil {
  109. global.GVA_LOG.Error("查询失败!", zap.Error(err))
  110. response.FailWithMessage("查询失败", c)
  111. return
  112. }
  113. response.OkWithData(reinfo, c)
  114. }
  115. // GetInfoList 分页获取公告列表
  116. // @Tags Info
  117. // @Summary 分页获取公告列表
  118. // @Security ApiKeyAuth
  119. // @accept application/json
  120. // @Produce application/json
  121. // @Param data query request.InfoSearch true "分页获取公告列表"
  122. // @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
  123. // @Router /info/getInfoList [get]
  124. func (a *info) GetInfoList(c *gin.Context) {
  125. var pageInfo request.InfoSearch
  126. err := c.ShouldBindQuery(&pageInfo)
  127. if err != nil {
  128. response.FailWithMessage(err.Error(), c)
  129. return
  130. }
  131. list, total, err := serviceInfo.GetInfoInfoList(pageInfo)
  132. if err != nil {
  133. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  134. response.FailWithMessage("获取失败", c)
  135. return
  136. }
  137. response.OkWithDetailed(response.PageResult{
  138. List: list,
  139. Total: total,
  140. Page: pageInfo.Page,
  141. PageSize: pageInfo.PageSize,
  142. }, "获取成功", c)
  143. }
  144. // GetInfoDataSource 获取Info的数据源
  145. // @Tags Info
  146. // @Summary 获取Info的数据源
  147. // @accept application/json
  148. // @Produce application/json
  149. // @Success 200 {object} response.Response{data=object,msg=string} "查询成功"
  150. // @Router /info/getInfoDataSource [get]
  151. func (a *info) GetInfoDataSource(c *gin.Context) {
  152. // 此接口为获取数据源定义的数据
  153. dataSource, err := serviceInfo.GetInfoDataSource()
  154. if err != nil {
  155. global.GVA_LOG.Error("查询失败!", zap.Error(err))
  156. response.FailWithMessage("查询失败", c)
  157. return
  158. }
  159. response.OkWithData(dataSource, c)
  160. }
  161. // GetInfoPublic 不需要鉴权的公告接口
  162. // @Tags Info
  163. // @Summary 不需要鉴权的公告接口
  164. // @accept application/json
  165. // @Produce application/json
  166. // @Param data query request.InfoSearch true "分页获取公告列表"
  167. // @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
  168. // @Router /info/getInfoPublic [get]
  169. func (a *info) GetInfoPublic(c *gin.Context) {
  170. // 此接口不需要鉴权 示例为返回了一个固定的消息接口,一般本接口用于C端服务,需要自己实现业务逻辑
  171. response.OkWithDetailed(gin.H{"info": "不需要鉴权的公告接口信息"}, "获取成功", c)
  172. }