gatewayipadmin.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package admin
  2. import (
  3. "github.com/gin-gonic/gin"
  4. v1 "github.com/go-nunu/nunu-layout-advanced/api/v1"
  5. v1admin "github.com/go-nunu/nunu-layout-advanced/api/v1/admin"
  6. "github.com/go-nunu/nunu-layout-advanced/internal/handler"
  7. "github.com/go-nunu/nunu-layout-advanced/internal/model"
  8. "github.com/go-nunu/nunu-layout-advanced/internal/service/admin"
  9. "net/http"
  10. )
  11. type GatewayIpAdminHandler struct {
  12. *handler.Handler
  13. gatewayIpAdminService admin.GatewayIpAdminService
  14. }
  15. func NewGatewayIpAdminHandler(
  16. handler *handler.Handler,
  17. gatewayIpAdminService admin.GatewayIpAdminService,
  18. ) *GatewayIpAdminHandler {
  19. return &GatewayIpAdminHandler{
  20. Handler: handler,
  21. gatewayIpAdminService: gatewayIpAdminService,
  22. }
  23. }
  24. func (h *GatewayIpAdminHandler) GetGatewayIpAdmin(ctx *gin.Context) {
  25. var req v1admin.GatewayIp
  26. if err := ctx.ShouldBind(&req); err != nil {
  27. v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, nil)
  28. return
  29. }
  30. res, err := h.gatewayIpAdminService.GetGatewayIpAdmin(ctx, int64(req.Id))
  31. if err != nil {
  32. v1.HandleError(ctx, http.StatusUnauthorized, v1.ErrUnauthorized, nil)
  33. return
  34. }
  35. v1.HandleSuccess(ctx, res)
  36. }
  37. func (h *GatewayIpAdminHandler) GetGatewayIpAdminList(ctx *gin.Context) {
  38. var req v1admin.SearchGatewayIpParams
  39. if err := ctx.ShouldBind(&req); err != nil {
  40. v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, nil)
  41. return
  42. }
  43. res, err := h.gatewayIpAdminService.GetGatewayGroupIpList(ctx, req)
  44. if err != nil {
  45. v1.HandleError(ctx, http.StatusInternalServerError, v1.ErrInternalServerError, nil)
  46. return
  47. }
  48. v1.HandleSuccess(ctx, res)
  49. }
  50. func (h *GatewayIpAdminHandler) AddGatewayIpAdmin(ctx *gin.Context) {
  51. var req model.Gatewayip
  52. if err := ctx.ShouldBind(&req); err != nil {
  53. v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, nil)
  54. return
  55. }
  56. err := h.gatewayIpAdminService.AddGatewayIp(ctx, req)
  57. if err != nil {
  58. v1.HandleError(ctx, http.StatusInternalServerError, v1.ErrInternalServerError, nil)
  59. return
  60. }
  61. v1.HandleSuccess(ctx, nil)
  62. }
  63. func (h *GatewayIpAdminHandler) EditGatewayIpAdmin(ctx *gin.Context) {
  64. var req model.Gatewayip
  65. if err := ctx.ShouldBind(&req); err != nil {
  66. v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, nil)
  67. return
  68. }
  69. err := h.gatewayIpAdminService.EditGatewayIp(ctx, req)
  70. if err != nil {
  71. v1.HandleError(ctx, http.StatusInternalServerError, v1.ErrInternalServerError, nil)
  72. return
  73. }
  74. v1.HandleSuccess(ctx, nil)
  75. }
  76. func (h *GatewayIpAdminHandler) DeleteGatewayIpAdmin(ctx *gin.Context) {
  77. var req v1admin.GatewayIp
  78. if err := ctx.ShouldBind(&req); err != nil {
  79. v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, nil)
  80. return
  81. }
  82. err := h.gatewayIpAdminService.DeleteGatewayIp(ctx, int64(req.Id))
  83. if err != nil {
  84. v1.HandleError(ctx, http.StatusInternalServerError, v1.ErrInternalServerError, nil)
  85. return
  86. }
  87. v1.HandleSuccess(ctx, nil)
  88. }
  89. func (h *GatewayIpAdminHandler) DeleteGatewayIpsAdmin(ctx *gin.Context) {
  90. var req v1admin.DeleteGatewayIpRequest
  91. if err := ctx.ShouldBind(&req); err != nil {
  92. v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, nil)
  93. return
  94. }
  95. err := h.gatewayIpAdminService.DeleteGatewayIps(ctx, req.Ids)
  96. if err != nil {
  97. v1.HandleError(ctx, http.StatusInternalServerError, v1.ErrInternalServerError, nil)
  98. return
  99. }
  100. v1.HandleSuccess(ctx, nil)
  101. }