Prechádzať zdrojové kódy

feat(gateway): 添加网关组 IP 相关的模型、仓库和处理器

- 新增 GateWayGroupIp 模型,用于表示网关组 IP 信息
- 实现 GateWayGroupIpRepository接口,提供网关组 IP 的数据库操作方法
- 创建 GateWayGroupIpService 服务,封装网关组 IP 的业务逻辑- 添加 GateWayGroupIpHandler处理器,用于处理网关组 IP 相关的 HTTP 请求
fusu 1 mesiac pred
rodič
commit
5196f21061

+ 25 - 0
internal/handler/gatewaygroupip.go

@@ -0,0 +1,25 @@
+package handler
+
+import (
+	"github.com/gin-gonic/gin"
+	"github.com/go-nunu/nunu-layout-advanced/internal/service"
+)
+
+type GateWayGroupIpHandler struct {
+	*Handler
+	gateWayGroupIpService service.GateWayGroupIpService
+}
+
+func NewGateWayGroupIpHandler(
+    handler *Handler,
+    gateWayGroupIpService service.GateWayGroupIpService,
+) *GateWayGroupIpHandler {
+	return &GateWayGroupIpHandler{
+		Handler:      handler,
+		gateWayGroupIpService: gateWayGroupIpService,
+	}
+}
+
+func (h *GateWayGroupIpHandler) GetGateWayGroupIp(ctx *gin.Context) {
+
+}

+ 18 - 0
internal/model/gatewaygroupip.go

@@ -0,0 +1,18 @@
+package model
+
+import "time"
+
+type GateWayGroupIp struct {
+	Id               int `gorm:"primary"`
+	GatewayGroupId   int `gorm:"not null"`
+	Ip               string `gorm:"not null"`
+	Tag              string `gorm:"null"`
+	Comment          string `gorm:"null"`
+	OriginPlace      string `gorm:"null"`
+	CreatedAt        time.Time
+	UpdatedAt        time.Time
+}
+
+func (m *GateWayGroupIp) TableName() string {
+    return "shd_waf_gateway_group_ip"
+}

+ 64 - 0
internal/repository/gatewaygroupip.go

@@ -0,0 +1,64 @@
+package repository
+
+import (
+    "context"
+	"github.com/go-nunu/nunu-layout-advanced/internal/model"
+)
+
+type GateWayGroupIpRepository interface {
+	GetGateWayGroupIp(ctx context.Context, id int64) (*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
+	GetGateWayGroupIpByGatewayGroupId(ctx context.Context, gatewayGroupId int) ([]model.GateWayGroupIp, error)
+}
+
+func NewGateWayGroupIpRepository(
+	repository *Repository,
+) GateWayGroupIpRepository {
+	return &gateWayGroupIpRepository{
+		Repository: repository,
+	}
+}
+
+type gateWayGroupIpRepository struct {
+	*Repository
+}
+
+func (r *gateWayGroupIpRepository) GetGateWayGroupIp(ctx context.Context, id int64) (*model.GateWayGroupIp, error) {
+	var gateWayGroupIp model.GateWayGroupIp
+
+	return &gateWayGroupIp, nil
+}
+
+func (r *gateWayGroupIpRepository) AddGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error {
+	if err := r.DB(ctx).Create(req).Error; err != nil {
+		return err
+	}
+	return nil
+}
+
+func (r *gateWayGroupIpRepository) EditGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error {
+	if err := r.DB(ctx).Model(&model.GateWayGroupIp{}).Where("id = ?", req.Id).Updates(req).Error; err != nil {
+		return err
+	}
+	return nil
+
+}
+
+func (r *gateWayGroupIpRepository) DeleteGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error {
+	if err := r.DB(ctx).Model(&model.GateWayGroupIp{}).Where("id = ?", req.Id).Delete(req).Error; err != nil {
+		return err
+	}
+	return nil
+
+}
+
+func (r *gateWayGroupIpRepository) GetGateWayGroupIpByGatewayGroupId(ctx context.Context, gatewayGroupId int) ([]model.GateWayGroupIp, error) {
+	var res []model.GateWayGroupIp
+	if err := r.DB(ctx).Model(&model.GateWayGroupIp{}).Where("gateway_group_id = ?", gatewayGroupId).Find(&res).Error; err != nil {
+		return nil, err
+	}
+	return res, nil
+
+}

+ 62 - 0
internal/service/gatewaygroupip.go

@@ -0,0 +1,62 @@
+package service
+
+import (
+    "context"
+	"github.com/go-nunu/nunu-layout-advanced/internal/model"
+	"github.com/go-nunu/nunu-layout-advanced/internal/repository"
+)
+
+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
+}
+func NewGateWayGroupIpService(
+    service *Service,
+    gateWayGroupIpRepository repository.GateWayGroupIpRepository,
+) GateWayGroupIpService {
+	return &gateWayGroupIpService{
+		Service:        service,
+		gateWayGroupIpRepository: gateWayGroupIpRepository,
+	}
+}
+
+type gateWayGroupIpService struct {
+	*Service
+	gateWayGroupIpRepository repository.GateWayGroupIpRepository
+}
+
+func (s *gateWayGroupIpService) GetGateWayGroupIp(ctx context.Context, id int64) (*model.GateWayGroupIp, error) {
+	return s.gateWayGroupIpRepository.GetGateWayGroupIp(ctx, id)
+}
+
+func (s *gateWayGroupIpService) GetGateWayGroupIpByGatewayGroupId(ctx context.Context, gatewayGroupId int) (*[]model.GateWayGroupIp, error) {
+	res, err :=  s.gateWayGroupIpRepository.GetGateWayGroupIpByGatewayGroupId(ctx, gatewayGroupId)
+	if err != nil {
+		return nil, err
+	}
+	return &res, nil
+}
+
+func (s *gateWayGroupIpService) AddGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error {
+	if err := s.gateWayGroupIpRepository.AddGateWayGroupIp(ctx, req); 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 {
+		return err
+	}
+	return nil
+}
+
+func (s *gateWayGroupIpService) DeleteGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error {
+	if err := s.gateWayGroupIpRepository.DeleteGateWayGroupIp(ctx, req); err != nil {
+		return err
+	}
+	return nil
+}