setting_controller.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package settings
  2. import (
  3. "errors"
  4. "nginx-ui/server/base"
  5. "nginx-ui/server/models"
  6. )
  7. type SettingController struct {
  8. base.Controller
  9. }
  10. // List 新增或者修改用户
  11. func (c *SettingController) List() {
  12. current := c.RequiredUser()
  13. if current == nil {
  14. return
  15. }
  16. list, err := SettingSrv.GetList(ListVo{})
  17. if err != nil {
  18. c.ErrorJson(err)
  19. return
  20. }
  21. c.SetData(list).Json()
  22. }
  23. // Save 新增或者修改用户
  24. func (c *SettingController) Save() {
  25. current := c.RequiredUser()
  26. if current == nil {
  27. return
  28. }
  29. organize := models.Setting{}
  30. if !c.ReadBody(&organize) {
  31. return
  32. }
  33. if organize.ConfigKey == "" {
  34. c.ErrorJson(errors.New("请输入配置的Key"))
  35. return
  36. }
  37. resp, err := SettingSrv.Save(&organize)
  38. if err != nil {
  39. c.ErrorJson(err)
  40. return
  41. }
  42. c.SetData(resp).Json()
  43. }
  44. func (c *SettingController) Delete() {
  45. current := c.RequiredUser()
  46. if current == nil {
  47. return
  48. }
  49. id, err := c.GetIntQuery("id")
  50. if err != nil {
  51. c.ErrorJson(err)
  52. return
  53. }
  54. err = SettingSrv.Delete(id)
  55. if err != nil {
  56. c.ErrorJson(err)
  57. return
  58. }
  59. c.Json()
  60. }