gatewaygroupip.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. }
  13. func NewGateWayGroupIpRepository(
  14. repository *Repository,
  15. ) GateWayGroupIpRepository {
  16. return &gateWayGroupIpRepository{
  17. Repository: repository,
  18. }
  19. }
  20. type gateWayGroupIpRepository struct {
  21. *Repository
  22. }
  23. func (r *gateWayGroupIpRepository) GetGateWayGroupIp(ctx context.Context, id int64) (*model.GateWayGroupIp, error) {
  24. var gateWayGroupIp model.GateWayGroupIp
  25. return &gateWayGroupIp, nil
  26. }
  27. func (r *gateWayGroupIpRepository) AddGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error {
  28. if err := r.DB(ctx).Create(req).Error; err != nil {
  29. return err
  30. }
  31. return nil
  32. }
  33. func (r *gateWayGroupIpRepository) EditGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error {
  34. if err := r.DB(ctx).Model(&model.GateWayGroupIp{}).Where("id = ?", req.Id).Updates(req).Error; err != nil {
  35. return err
  36. }
  37. return nil
  38. }
  39. func (r *gateWayGroupIpRepository) DeleteGateWayGroupIp(ctx context.Context, req *model.GateWayGroupIp) error {
  40. if err := r.DB(ctx).Model(&model.GateWayGroupIp{}).Where("id = ?", req.Id).Delete(req).Error; err != nil {
  41. return err
  42. }
  43. return nil
  44. }
  45. func (r *gateWayGroupIpRepository) GetGateWayGroupIpByGatewayGroupId(ctx context.Context, gatewayGroupId int) ([]model.GateWayGroupIp, error) {
  46. var res []model.GateWayGroupIp
  47. if err := r.DB(ctx).Model(&model.GateWayGroupIp{}).Where("gateway_group_id = ?", gatewayGroupId).Find(&res).Error; err != nil {
  48. return nil, err
  49. }
  50. return res, nil
  51. }