소스 검색

feat(gateway): 添加网关组 IP 相关接口和功能- 新增 GetGateWayGroupIpByGatewayGroupId、AddGateWayGroupIp、EditGateWayGroupIp 和 DeleteGateWayGroupIp 接口
- 实现网关组 IP 的获取、添加、编辑和删除功能
- 添加相关请求和响应结构体
- 更新路由配置,支持新的网关组 IP 接口

fusu 1 개월 전
부모
커밋
8a47a8bc06
5개의 변경된 파일117개의 추가작업 그리고 10개의 파일을 삭제
  1. 18 0
      api/v1/gateWayGroupIp.go
  2. 3 1
      cmd/server/wire/wire_gen.go
  3. 65 0
      internal/handler/gatewaygroupip.go
  4. 6 0
      internal/server/http.go
  5. 25 9
      internal/service/gatewaygroupip.go

+ 18 - 0
api/v1/gateWayGroupIp.go

@@ -0,0 +1,18 @@
+package v1
+
+type GetGateWayGroupIpByGatewayGroupIdRequest struct {
+	GatewayGroupId int `form:"gatewayGroupId" json:"gatewayGroupId" binding:"required"`
+}
+
+type GateWayGroupIpRequest struct {
+	Id             int    `json:"id" form:"id"`
+	GatewayGroupId int    `json:"gatewayGroupId" form:"gatewayGroupId" binding:"required"`
+	Ip             string `json:"ip" form:"ip" binding:"required"`
+	Tag            string `json:"tag" form:"tag"`
+	OriginPlace      string `json:"originPlace" form:"originPlace"`
+	Comment        string `json:"comment" form:"comment"`
+}
+
+type DeleteGateWayGroupIpRequest struct {
+	Id int `json:"id" form:"id" binding:"required"`
+}

+ 3 - 1
cmd/server/wire/wire_gen.go

@@ -89,7 +89,9 @@ func NewWire(viperViper *viper.Viper, logger *log.Logger) (*app.App, func(), err
 	adminService := service.NewAdminService(serviceService, adminRepository)
 	adminHandler := handler.NewAdminHandler(handlerHandler, adminService)
 	gatewayGroupHandler := handler.NewGatewayGroupHandler(handlerHandler, gatewayGroupService)
-	httpServer := server.NewHTTPServer(logger, viperViper, jwtJWT, syncedEnforcer, limiterLimiter, handlerFunc, userHandler, gameShieldHandler, gameShieldBackendHandler, webForwardingHandler, webLimitHandler, tcpforwardingHandler, udpForWardingHandler, tcpLimitHandler, udpLimitHandler, globalLimitHandler, adminHandler, gatewayGroupHandler)
+	gateWayGroupIpService := service.NewGateWayGroupIpService(serviceService, gateWayGroupIpRepository)
+	gateWayGroupIpHandler := handler.NewGateWayGroupIpHandler(handlerHandler, gateWayGroupIpService)
+	httpServer := server.NewHTTPServer(logger, viperViper, jwtJWT, syncedEnforcer, limiterLimiter, handlerFunc, userHandler, gameShieldHandler, gameShieldBackendHandler, webForwardingHandler, webLimitHandler, tcpforwardingHandler, udpForWardingHandler, tcpLimitHandler, udpLimitHandler, globalLimitHandler, adminHandler, gatewayGroupHandler, gateWayGroupIpHandler)
 	appApp := newApp(httpServer)
 	return appApp, func() {
 		cleanup()

+ 65 - 0
internal/handler/gatewaygroupip.go

@@ -2,7 +2,9 @@ package handler
 
 import (
 	"github.com/gin-gonic/gin"
+	v1 "github.com/go-nunu/nunu-layout-advanced/api/v1"
 	"github.com/go-nunu/nunu-layout-advanced/internal/service"
+	"net/http"
 )
 
 type GateWayGroupIpHandler struct {
@@ -23,3 +25,66 @@ func NewGateWayGroupIpHandler(
 func (h *GateWayGroupIpHandler) GetGateWayGroupIp(ctx *gin.Context) {
 
 }
+
+func (h *GateWayGroupIpHandler) GetGateWayGroupIpByGatewayGroupId(ctx *gin.Context)  {
+	req := new(v1.GetGateWayGroupIpByGatewayGroupIdRequest)
+	if err := ctx.ShouldBind(req); err != nil {
+		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest,nil)
+		return
+	}
+	res, err := h.gateWayGroupIpService.GetGateWayGroupIpByGatewayGroupId(ctx, req.GatewayGroupId)
+	if err != nil {
+		v1.HandleError(ctx, http.StatusInternalServerError, err, nil)
+		return
+	}
+
+	v1.HandleSuccess(ctx, res)
+}
+
+func (h *GateWayGroupIpHandler) AddGateWayGroupIp(ctx *gin.Context)  {
+	req := new(v1.GateWayGroupIpRequest)
+	if err := ctx.ShouldBind(req); err != nil {
+		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
+		return
+	}
+
+	err := h.gateWayGroupIpService.AddGateWayGroupIp(ctx, req)
+	if err != nil {
+		v1.HandleError(ctx, http.StatusInternalServerError, err, err.Error())
+		return
+	}
+	v1.HandleSuccess(ctx, nil)
+
+}
+
+func (h *GateWayGroupIpHandler) EditGateWayGroupIp(ctx *gin.Context)  {
+	req := new(v1.GateWayGroupIpRequest)
+	if err := ctx.ShouldBind(req); err != nil {
+		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
+		return
+	}
+
+	err := h.gateWayGroupIpService.EditGateWayGroupIp(ctx, req)
+	if err != nil {
+		v1.HandleError(ctx, http.StatusInternalServerError, err, err.Error())
+		return
+	}
+	v1.HandleSuccess(ctx, nil)
+
+}
+
+func (h *GateWayGroupIpHandler) DeleteGateWayGroupIp(ctx *gin.Context)  {
+	req := new(v1.DeleteGateWayGroupIpRequest)
+	if err := ctx.ShouldBind(req); err != nil {
+		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
+		return
+	}
+
+	err := h.gateWayGroupIpService.DeleteGateWayGroupIp(ctx, req)
+	if err != nil {
+		v1.HandleError(ctx, http.StatusInternalServerError, err, err.Error())
+		return
+	}
+	v1.HandleSuccess(ctx, nil)
+
+}

+ 6 - 0
internal/server/http.go

@@ -35,6 +35,7 @@ func NewHTTPServer(
 	globalLimitHandler *handler.GlobalLimitHandler,
 	adminHandler *handler.AdminHandler,
 	gatewayHandler *handler.GatewayGroupHandler,
+	gatewayIpHandler *handler.GateWayGroupIpHandler,
 
 ) *http.Server {
 	gin.SetMode(gin.DebugMode)
@@ -166,6 +167,11 @@ func NewHTTPServer(
 			strictAuthRouter.POST("/gateway/add", gatewayHandler.AddGatewayGroup)
 			strictAuthRouter.PUT("/gateway/edit", gatewayHandler.EditGatewayGroup)
 			strictAuthRouter.DELETE("/gateway/del", gatewayHandler.DeleteGatewayGroup)
+
+			strictAuthRouter.GET("/gatewayIp/get", gatewayIpHandler.GetGateWayGroupIpByGatewayGroupId)
+			strictAuthRouter.POST("/gatewayIp/add", gatewayIpHandler.AddGateWayGroupIp)
+			strictAuthRouter.PUT("/gatewayIp/edit", gatewayIpHandler.EditGateWayGroupIp)
+			strictAuthRouter.DELETE("/gatewayIp/del", gatewayIpHandler.DeleteGateWayGroupIp)
 		}
 	}
 

+ 25 - 9
internal/service/gatewaygroupip.go

@@ -2,6 +2,7 @@ package service
 
 import (
 	"context"
+	v1 "github.com/go-nunu/nunu-layout-advanced/api/v1"
 
 	"github.com/go-nunu/nunu-layout-advanced/internal/model"
 	"github.com/go-nunu/nunu-layout-advanced/internal/repository"
@@ -10,9 +11,9 @@ import (
 type GateWayGroupIpService interface {
 	GetGateWayGroupIp(ctx context.Context, id int64) (*model.GateWayGroupIp, error)
 	GetGateWayGroupIpByGatewayGroupId(ctx context.Context, gatewayGroupId int) (*[]model.GateWayGroupIp, error)
-	AddGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error
-	EditGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error
-	DeleteGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error
+	AddGateWayGroupIp(ctx context.Context,  req *v1.GateWayGroupIpRequest) error
+	EditGateWayGroupIp(ctx context.Context,  req *v1.GateWayGroupIpRequest) error
+	DeleteGateWayGroupIp(ctx context.Context, req *v1.DeleteGateWayGroupIpRequest) error
 }
 
 func NewGateWayGroupIpService(
@@ -42,22 +43,37 @@ func (s *gateWayGroupIpService) GetGateWayGroupIpByGatewayGroupId(ctx context.Co
 	return &res, nil
 }
 
-func (s *gateWayGroupIpService) AddGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error {
-	if err := s.gateWayGroupIpRepository.AddGateWayGroupIp(ctx, req); err != nil {
+func (s *gateWayGroupIpService) AddGateWayGroupIp(ctx context.Context, req *v1.GateWayGroupIpRequest) error {
+	if err := s.gateWayGroupIpRepository.AddGateWayGroupIp(ctx, &model.GateWayGroupIp{
+		GatewayGroupId: req.GatewayGroupId,
+		Ip:             req.Ip,
+		Tag:            req.Tag,
+		Comment:        req.Comment,
+		OriginPlace:    req.OriginPlace,
+	}); err != nil {
 		return err
 	}
 	return nil
 }
 
-func (s *gateWayGroupIpService) EditGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error {
-	if err := s.gateWayGroupIpRepository.EditGateWayGroupIp(ctx, req); err != nil {
+func (s *gateWayGroupIpService) EditGateWayGroupIp(ctx context.Context, req *v1.GateWayGroupIpRequest) error {
+	if err := s.gateWayGroupIpRepository.EditGateWayGroupIp(ctx, &model.GateWayGroupIp{
+		Id:             req.Id,
+		GatewayGroupId: req.GatewayGroupId,
+		Ip:             req.Ip,
+		Tag:            req.Tag,
+		Comment:        req.Comment,
+		OriginPlace:    req.OriginPlace,
+	}); err != nil {
 		return err
 	}
 	return nil
 }
 
-func (s *gateWayGroupIpService) DeleteGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error {
-	if err := s.gateWayGroupIpRepository.DeleteGateWayGroupIp(ctx, req); err != nil {
+func (s *gateWayGroupIpService) DeleteGateWayGroupIp(ctx context.Context, req *v1.DeleteGateWayGroupIpRequest) error {
+	if err := s.gateWayGroupIpRepository.DeleteGateWayGroupIp(ctx, &model.GateWayGroupIp{
+		Id: req.Id,
+	}); err != nil {
 		return err
 	}
 	return nil