gatewaygroupip.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package service
  2. import (
  3. "context"
  4. v1 "github.com/go-nunu/nunu-layout-advanced/api/v1"
  5. "github.com/go-nunu/nunu-layout-advanced/internal/model"
  6. "github.com/go-nunu/nunu-layout-advanced/internal/repository"
  7. )
  8. type GateWayGroupIpService interface {
  9. GetGateWayGroupIp(ctx context.Context, id int64) (*model.GateWayGroupIp, error)
  10. GetGateWayGroupIpByGatewayGroupId(ctx context.Context, gatewayGroupId int) (*[]model.GateWayGroupIp, error)
  11. AddGateWayGroupIp(ctx context.Context, req *v1.GateWayGroupIpRequest) error
  12. EditGateWayGroupIp(ctx context.Context, req *v1.GateWayGroupIpRequest) error
  13. DeleteGateWayGroupIp(ctx context.Context, req *v1.DeleteGateWayGroupIpRequest) error
  14. }
  15. func NewGateWayGroupIpService(
  16. service *Service,
  17. gateWayGroupIpRepository repository.GateWayGroupIpRepository,
  18. ) GateWayGroupIpService {
  19. return &gateWayGroupIpService{
  20. Service: service,
  21. gateWayGroupIpRepository: gateWayGroupIpRepository,
  22. }
  23. }
  24. type gateWayGroupIpService struct {
  25. *Service
  26. gateWayGroupIpRepository repository.GateWayGroupIpRepository
  27. }
  28. func (s *gateWayGroupIpService) GetGateWayGroupIp(ctx context.Context, id int64) (*model.GateWayGroupIp, error) {
  29. return s.gateWayGroupIpRepository.GetGateWayGroupIp(ctx, id)
  30. }
  31. func (s *gateWayGroupIpService) GetGateWayGroupIpByGatewayGroupId(ctx context.Context, gatewayGroupId int) (*[]model.GateWayGroupIp, error) {
  32. res, err := s.gateWayGroupIpRepository.GetGateWayGroupIpByGatewayGroupId(ctx, gatewayGroupId)
  33. if err != nil {
  34. return nil, err
  35. }
  36. return &res, nil
  37. }
  38. func (s *gateWayGroupIpService) AddGateWayGroupIp(ctx context.Context, req *v1.GateWayGroupIpRequest) error {
  39. if err := s.gateWayGroupIpRepository.AddGateWayGroupIp(ctx, &model.GateWayGroupIp{
  40. GatewayGroupId: req.GatewayGroupId,
  41. Ip: req.Ip,
  42. Tag: req.Tag,
  43. Comment: req.Comment,
  44. OriginPlace: req.OriginPlace,
  45. }); err != nil {
  46. return err
  47. }
  48. return nil
  49. }
  50. func (s *gateWayGroupIpService) EditGateWayGroupIp(ctx context.Context, req *v1.GateWayGroupIpRequest) error {
  51. if err := s.gateWayGroupIpRepository.EditGateWayGroupIp(ctx, &model.GateWayGroupIp{
  52. Id: req.Id,
  53. GatewayGroupId: req.GatewayGroupId,
  54. Ip: req.Ip,
  55. Tag: req.Tag,
  56. Comment: req.Comment,
  57. OriginPlace: req.OriginPlace,
  58. }); err != nil {
  59. return err
  60. }
  61. return nil
  62. }
  63. func (s *gateWayGroupIpService) DeleteGateWayGroupIp(ctx context.Context, req *v1.DeleteGateWayGroupIpRequest) error {
  64. if err := s.gateWayGroupIpRepository.DeleteGateWayGroupIp(ctx, &model.GateWayGroupIp{
  65. Id: req.Id,
  66. }); err != nil {
  67. return err
  68. }
  69. return nil
  70. }