gatewaygroupip.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package repository
  2. import (
  3. "context"
  4. "github.com/go-nunu/nunu-layout-advanced/internal/model"
  5. )
  6. type GateWayGroupIpRepository interface {
  7. GetGateWayGroupIp(ctx context.Context, id int64) (*model.GateWayGroupIp, error)
  8. AddGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error
  9. EditGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error
  10. DeleteGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error
  11. GetGateWayGroupIpByGatewayGroupId(ctx context.Context, gatewayGroupId int) ([]model.GateWayGroupIp, error)
  12. GetGateWayGroupFirstIpByGatewayGroupId(ctx context.Context, gatewayGroupId int) (string, error)
  13. GetGateWayGroupAllIpByGatewayGroupId(ctx context.Context, gatewayGroupId int) ([]string, error)
  14. }
  15. func NewGateWayGroupIpRepository(
  16. repository *Repository,
  17. ) GateWayGroupIpRepository {
  18. return &gateWayGroupIpRepository{
  19. Repository: repository,
  20. }
  21. }
  22. type gateWayGroupIpRepository struct {
  23. *Repository
  24. }
  25. func (r *gateWayGroupIpRepository) GetGateWayGroupIp(ctx context.Context, id int64) (*model.GateWayGroupIp, error) {
  26. var gateWayGroupIp model.GateWayGroupIp
  27. return &gateWayGroupIp, nil
  28. }
  29. func (r *gateWayGroupIpRepository) AddGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error {
  30. if err := r.DB(ctx).Create(req).Error; err != nil {
  31. return err
  32. }
  33. return nil
  34. }
  35. func (r *gateWayGroupIpRepository) EditGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error {
  36. if err := r.DB(ctx).Model(&model.GateWayGroupIp{}).Where("id = ?", req.Id).Updates(req).Error; err != nil {
  37. return err
  38. }
  39. return nil
  40. }
  41. func (r *gateWayGroupIpRepository) DeleteGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error {
  42. if err := r.DB(ctx).Model(&model.GateWayGroupIp{}).Where("id = ?", req.Id).Delete(req).Error; err != nil {
  43. return err
  44. }
  45. return nil
  46. }
  47. func (r *gateWayGroupIpRepository) GetGateWayGroupIpByGatewayGroupId(ctx context.Context, gatewayGroupId int) ([]model.GateWayGroupIp, error) {
  48. var res []model.GateWayGroupIp
  49. if err := r.DB(ctx).Model(&model.GateWayGroupIp{}).Where("gateway_group_id = ?", gatewayGroupId).Find(&res).Error; err != nil {
  50. return nil, err
  51. }
  52. return res, nil
  53. }
  54. func (r *gateWayGroupIpRepository) GetGateWayGroupFirstIpByGatewayGroupId(ctx context.Context, gatewayGroupId int) (string, error) {
  55. var res string
  56. if err := r.DB(ctx).Model(&model.GateWayGroupIp{}).Where("gateway_group_id = ?", gatewayGroupId).Select("ip").First(&res).Error; err != nil {
  57. return "", err
  58. }
  59. return res, nil
  60. }
  61. func (r *gateWayGroupIpRepository) GetGateWayGroupAllIpByGatewayGroupId(ctx context.Context, gatewayGroupId int) ([]string, error) {
  62. var res []string
  63. if err := r.DB(ctx).Model(&model.GateWayGroupIp{}).Where("gateway_group_id = ?", gatewayGroupId).Select("ip").Find(&res).Error; err != nil {
  64. return nil, err
  65. }
  66. return res, nil
  67. }