|
@@ -2,6 +2,7 @@ package service
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
+ "fmt"
|
|
|
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"
|
|
@@ -53,6 +54,13 @@ func (s *allowAndDenyIpService) GetAllowAndDenyIpsAllByHostId(ctx context.Contex
|
|
|
}
|
|
|
|
|
|
func (s *allowAndDenyIpService) AddAllowAndDenyIps(ctx context.Context, req v1.AllowAndDenyIpRequest) error {
|
|
|
+ // 判断ip是否存在
|
|
|
+ err := s.IsExistIp(ctx, int64(req.HostId), req.Ip)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
gatewayGroupIps, err := s.gatewayGroupIp.GetGateWayGroupIpByHostId(ctx, req.HostId)
|
|
|
if err != nil {
|
|
|
return err
|
|
@@ -77,6 +85,13 @@ func (s *allowAndDenyIpService) AddAllowAndDenyIps(ctx context.Context, req v1.A
|
|
|
}
|
|
|
|
|
|
func (s *allowAndDenyIpService) EditAllowAndDenyIps(ctx context.Context, req v1.AllowAndDenyIpRequest) error {
|
|
|
+ // 判断ip是否存在
|
|
|
+ err := s.IsExistIp(ctx, int64(req.HostId), req.Ip)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
gatewayGroupIps, err := s.gatewayGroupIp.GetGateWayGroupIpByHostId(ctx, req.HostId)
|
|
|
if err != nil {
|
|
|
return err
|
|
@@ -139,3 +154,13 @@ func (s *allowAndDenyIpService) DeleteAllowAndDenyIps(ctx context.Context, req v
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+func (s *allowAndDenyIpService) IsExistIp(ctx context.Context, hostId int64, Ip string) error {
|
|
|
+ count, err := s.allowAndDenyIpRepository.GetIpCount(ctx, hostId, Ip)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if count > 0 {
|
|
|
+ return fmt.Errorf("ip已存在,请勿重复添加")
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|