chart_theme.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_forum_hub/models"
  5. "eta/eta_forum_hub/services"
  6. )
  7. // ChartThemeController
  8. // @Description: 图表主题配置模块
  9. type ChartThemeController struct {
  10. BaseAuthController
  11. }
  12. // Save
  13. // @Title 新增或编辑主题
  14. // @Description
  15. // @Param request body request.DeleteThemeConfReq true "type json string"
  16. // @Success 200 Ret=200 添加成功
  17. // @router /theme/save [post]
  18. func (c *ChartThemeController) Save() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. c.Data["json"] = br
  22. c.ServeJSON()
  23. }()
  24. var req models.ChartTheme
  25. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  26. if err != nil {
  27. br.Msg = "参数解析异常!"
  28. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  29. return
  30. }
  31. if req.ChartThemeTypeId <= 0 {
  32. br.Msg = "请选择图表类型"
  33. br.IsSendEmail = false
  34. return
  35. }
  36. // 添加入库
  37. err = services.AddOrUpdateChartTheme(req)
  38. if err != nil {
  39. br.Msg = "添加失败"
  40. br.ErrMsg = "添加失败,Err:" + err.Error()
  41. return
  42. }
  43. br.Ret = 200
  44. br.Success = true
  45. br.Msg = "添加成功"
  46. }
  47. // ThemeTypeSave
  48. // @Title 新增或编辑主题类型
  49. // @Description
  50. // @Param request body request.DeleteThemeConfReq true "type json string"
  51. // @Success 200 Ret=200 添加成功
  52. // @router /theme/type/save [post]
  53. func (c *ChartThemeController) ThemeTypeSave() {
  54. br := new(models.BaseResponse).Init()
  55. defer func() {
  56. c.Data["json"] = br
  57. c.ServeJSON()
  58. }()
  59. var req models.ChartThemeType
  60. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  61. if err != nil {
  62. br.Msg = "参数解析异常!"
  63. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  64. return
  65. }
  66. // 添加入库
  67. err = services.AddOrUpdateChartThemeType(req)
  68. if err != nil {
  69. br.Msg = "添加失败"
  70. br.ErrMsg = "添加失败,Err:" + err.Error()
  71. return
  72. }
  73. br.Ret = 200
  74. br.Success = true
  75. br.Msg = "添加成功"
  76. }