exa_attachment_category.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package example
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. common "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
  5. "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
  6. "github.com/flipped-aurora/gin-vue-admin/server/model/example"
  7. "github.com/gin-gonic/gin"
  8. "go.uber.org/zap"
  9. )
  10. type AttachmentCategoryApi struct{}
  11. // GetCategoryList
  12. // @Tags GetCategoryList
  13. // @Summary 媒体库分类列表
  14. // @Security AttachmentCategory
  15. // @Produce application/json
  16. // @Success 200 {object} response.Response{data=example.ExaAttachmentCategory,msg=string} "媒体库分类列表"
  17. // @Router /attachmentCategory/getCategoryList [get]
  18. func (a *AttachmentCategoryApi) GetCategoryList(c *gin.Context) {
  19. res, err := attachmentCategoryService.GetCategoryList()
  20. if err != nil {
  21. global.GVA_LOG.Error("获取分类列表失败!", zap.Error(err))
  22. response.FailWithMessage("获取分类列表失败", c)
  23. return
  24. }
  25. response.OkWithData(res, c)
  26. }
  27. // AddCategory
  28. // @Tags AddCategory
  29. // @Summary 添加媒体库分类
  30. // @Security AttachmentCategory
  31. // @accept application/json
  32. // @Produce application/json
  33. // @Param data body example.ExaAttachmentCategory true "媒体库分类数据"// @Success 200 {object} response.Response{msg=string} "添加媒体库分类"
  34. // @Router /attachmentCategory/addCategory [post]
  35. func (a *AttachmentCategoryApi) AddCategory(c *gin.Context) {
  36. var req example.ExaAttachmentCategory
  37. if err := c.ShouldBindJSON(&req); err != nil {
  38. global.GVA_LOG.Error("参数错误!", zap.Error(err))
  39. response.FailWithMessage("参数错误", c)
  40. return
  41. }
  42. if err := attachmentCategoryService.AddCategory(&req); err != nil {
  43. global.GVA_LOG.Error("创建/更新失败!", zap.Error(err))
  44. response.FailWithMessage("创建/更新失败:"+err.Error(), c)
  45. return
  46. }
  47. response.OkWithMessage("创建/更新成功", c)
  48. }
  49. // DeleteCategory
  50. // @Tags DeleteCategory
  51. // @Summary 删除分类
  52. // @Security AttachmentCategory
  53. // @accept application/json
  54. // @Produce application/json
  55. // @Param data body common.GetById true "分类id"
  56. // @Success 200 {object} response.Response{msg=string} "删除分类"
  57. // @Router /attachmentCategory/deleteCategory [post]
  58. func (a *AttachmentCategoryApi) DeleteCategory(c *gin.Context) {
  59. var req common.GetById
  60. if err := c.ShouldBindJSON(&req); err != nil {
  61. response.FailWithMessage("参数错误", c)
  62. return
  63. }
  64. if req.ID == 0 {
  65. response.FailWithMessage("参数错误", c)
  66. return
  67. }
  68. if err := attachmentCategoryService.DeleteCategory(&req.ID); err != nil {
  69. response.FailWithMessage("删除失败", c)
  70. return
  71. }
  72. response.OkWithMessage("删除成功", c)
  73. }