gatewaygroupip.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package handler
  2. import (
  3. "github.com/gin-gonic/gin"
  4. v1 "github.com/go-nunu/nunu-layout-advanced/api/v1"
  5. "github.com/go-nunu/nunu-layout-advanced/internal/service"
  6. "net/http"
  7. )
  8. type GateWayGroupIpHandler struct {
  9. *Handler
  10. gateWayGroupIpService service.GateWayGroupIpService
  11. }
  12. func NewGateWayGroupIpHandler(
  13. handler *Handler,
  14. gateWayGroupIpService service.GateWayGroupIpService,
  15. ) *GateWayGroupIpHandler {
  16. return &GateWayGroupIpHandler{
  17. Handler: handler,
  18. gateWayGroupIpService: gateWayGroupIpService,
  19. }
  20. }
  21. func (h *GateWayGroupIpHandler) GetGateWayGroupIp(ctx *gin.Context) {
  22. }
  23. func (h *GateWayGroupIpHandler) GetGateWayGroupIpByGatewayGroupId(ctx *gin.Context) {
  24. req := new(v1.GetGateWayGroupIpByGatewayGroupIdRequest)
  25. if err := ctx.ShouldBind(req); err != nil {
  26. v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest,nil)
  27. return
  28. }
  29. res, err := h.gateWayGroupIpService.GetGateWayGroupIpByGatewayGroupId(ctx, req.GatewayGroupId)
  30. if err != nil {
  31. v1.HandleError(ctx, http.StatusInternalServerError, err, nil)
  32. return
  33. }
  34. v1.HandleSuccess(ctx, res)
  35. }
  36. func (h *GateWayGroupIpHandler) AddGateWayGroupIp(ctx *gin.Context) {
  37. req := new(v1.GateWayGroupIpRequest)
  38. if err := ctx.ShouldBind(req); err != nil {
  39. v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
  40. return
  41. }
  42. err := h.gateWayGroupIpService.AddGateWayGroupIp(ctx, req)
  43. if err != nil {
  44. v1.HandleError(ctx, http.StatusInternalServerError, err, err.Error())
  45. return
  46. }
  47. v1.HandleSuccess(ctx, nil)
  48. }
  49. func (h *GateWayGroupIpHandler) EditGateWayGroupIp(ctx *gin.Context) {
  50. req := new(v1.GateWayGroupIpRequest)
  51. if err := ctx.ShouldBind(req); err != nil {
  52. v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
  53. return
  54. }
  55. err := h.gateWayGroupIpService.EditGateWayGroupIp(ctx, req)
  56. if err != nil {
  57. v1.HandleError(ctx, http.StatusInternalServerError, err, err.Error())
  58. return
  59. }
  60. v1.HandleSuccess(ctx, nil)
  61. }
  62. func (h *GateWayGroupIpHandler) DeleteGateWayGroupIp(ctx *gin.Context) {
  63. req := new(v1.DeleteGateWayGroupIpRequest)
  64. if err := ctx.ShouldBind(req); err != nil {
  65. v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
  66. return
  67. }
  68. err := h.gateWayGroupIpService.DeleteGateWayGroupIp(ctx, req)
  69. if err != nil {
  70. v1.HandleError(ctx, http.StatusInternalServerError, err, err.Error())
  71. return
  72. }
  73. v1.HandleSuccess(ctx, nil)
  74. }
  75. func (h *GateWayGroupIpHandler) GetGateWayGroupIpList(ctx *gin.Context) {
  76. req := new(v1.SearchGatewayGroupIpParams)
  77. if err := ctx.ShouldBind(req); err != nil {
  78. v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
  79. return
  80. }
  81. res, err := h.gateWayGroupIpService.GetGateWayGroupIpAdmin(ctx, req)
  82. if err != nil {
  83. v1.HandleError(ctx, http.StatusInternalServerError, err, err.Error())
  84. return
  85. }
  86. v1.HandleSuccess(ctx, res)
  87. }