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" ) 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 *v1.GateWayGroupIpRequest) error EditGateWayGroupIp(ctx context.Context, req *v1.GateWayGroupIpRequest) error DeleteGateWayGroupIp(ctx context.Context, req *v1.DeleteGateWayGroupIpRequest) error GetGateWayGroupIpAdmin(ctx context.Context,req *v1.SearchGatewayGroupIpParams) (*v1.PaginatedResponse[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 *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 *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 *v1.DeleteGateWayGroupIpRequest) error { if err := s.gateWayGroupIpRepository.DeleteGateWayGroupIp(ctx, &model.GateWayGroupIp{ Id: req.Id, }); err != nil { return err } return nil } func (s *gateWayGroupIpService) GetGateWayGroupIpAdmin(ctx context.Context,req *v1.SearchGatewayGroupIpParams) (*v1.PaginatedResponse[model.GateWayGroupIp], error) { res, err := s.gateWayGroupIpRepository.GetGatewayGroupIpList(ctx, *req) if err != nil { return nil, err } return res, nil }