route_controller.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package settings
  2. import (
  3. "nginx-ui/server/base"
  4. "nginx-ui/server/models"
  5. )
  6. type RouteController struct {
  7. base.Controller
  8. }
  9. // List 查看全部路由
  10. func (c *RouteController) List() {
  11. current := c.RequiredUser()
  12. if current == nil {
  13. return
  14. }
  15. listVo := RouteListVo{}
  16. if !c.ReadBody(&listVo) {
  17. return
  18. }
  19. if listVo.Uid == -1 {
  20. listVo.Uid = current.Id
  21. }
  22. list, err := Route.GetList(listVo)
  23. if err != nil {
  24. c.ErrorJson(err)
  25. return
  26. }
  27. c.SetData(list).Json()
  28. }
  29. // Save 新增或者修改用户
  30. func (c *RouteController) Save() {
  31. current := c.RequiredUser()
  32. if current == nil {
  33. return
  34. }
  35. route := models.SettingRoute{}
  36. if !c.ReadBody(&route) {
  37. return
  38. }
  39. if route.Uid == -1 {
  40. route.Uid = current.Id
  41. }
  42. resp, err := Route.Save(&route)
  43. if err != nil {
  44. c.ErrorJson(err)
  45. return
  46. }
  47. c.SetData(resp).Json()
  48. }
  49. func (c *RouteController) Delete() {
  50. current := c.RequiredUser()
  51. if current == nil {
  52. return
  53. }
  54. id := c.GetQuery("id")
  55. err := Route.Delete(id)
  56. if err != nil {
  57. c.ErrorJson(err)
  58. return
  59. }
  60. c.Json()
  61. }