gatewaygroupip.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. GetGateWayGroupIpAdmin(ctx context.Context,req *v1.SearchGatewayGroupIpParams) (*v1.PaginatedResponse[model.GateWayGroupIp], error)
  15. }
  16. func NewGateWayGroupIpService(
  17. service *Service,
  18. gateWayGroupIpRepository repository.GateWayGroupIpRepository,
  19. ) GateWayGroupIpService {
  20. return &gateWayGroupIpService{
  21. Service: service,
  22. gateWayGroupIpRepository: gateWayGroupIpRepository,
  23. }
  24. }
  25. type gateWayGroupIpService struct {
  26. *Service
  27. gateWayGroupIpRepository repository.GateWayGroupIpRepository
  28. }
  29. func (s *gateWayGroupIpService) GetGateWayGroupIp(ctx context.Context, id int64) (*model.GateWayGroupIp, error) {
  30. return s.gateWayGroupIpRepository.GetGateWayGroupIp(ctx, id)
  31. }
  32. func (s *gateWayGroupIpService) GetGateWayGroupIpByGatewayGroupId(ctx context.Context, gatewayGroupId int) (*[]model.GateWayGroupIp, error) {
  33. res, err := s.gateWayGroupIpRepository.GetGateWayGroupIpByGatewayGroupId(ctx, gatewayGroupId)
  34. if err != nil {
  35. return nil, err
  36. }
  37. return &res, nil
  38. }
  39. func (s *gateWayGroupIpService) AddGateWayGroupIp(ctx context.Context, req *v1.GateWayGroupIpRequest) error {
  40. if err := s.gateWayGroupIpRepository.AddGateWayGroupIp(ctx, &model.GateWayGroupIp{
  41. GatewayGroupId: req.GatewayGroupId,
  42. Ip: req.Ip,
  43. Tag: req.Tag,
  44. Comment: req.Comment,
  45. OriginPlace: req.OriginPlace,
  46. }); err != nil {
  47. return err
  48. }
  49. return nil
  50. }
  51. func (s *gateWayGroupIpService) EditGateWayGroupIp(ctx context.Context, req *v1.GateWayGroupIpRequest) error {
  52. if err := s.gateWayGroupIpRepository.EditGateWayGroupIp(ctx, &model.GateWayGroupIp{
  53. Id: req.Id,
  54. GatewayGroupId: req.GatewayGroupId,
  55. Ip: req.Ip,
  56. Tag: req.Tag,
  57. Comment: req.Comment,
  58. OriginPlace: req.OriginPlace,
  59. }); err != nil {
  60. return err
  61. }
  62. return nil
  63. }
  64. func (s *gateWayGroupIpService) DeleteGateWayGroupIp(ctx context.Context, req *v1.DeleteGateWayGroupIpRequest) error {
  65. if err := s.gateWayGroupIpRepository.DeleteGateWayGroupIp(ctx, &model.GateWayGroupIp{
  66. Id: req.Id,
  67. }); err != nil {
  68. return err
  69. }
  70. return nil
  71. }
  72. func (s *gateWayGroupIpService) GetGateWayGroupIpAdmin(ctx context.Context,req *v1.SearchGatewayGroupIpParams) (*v1.PaginatedResponse[model.GateWayGroupIp], error) {
  73. res, err := s.gateWayGroupIpRepository.GetGatewayGroupIpList(ctx, *req)
  74. if err != nil {
  75. return nil, err
  76. }
  77. return res, nil
  78. }