webforwarding.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package repository
  2. import (
  3. "context"
  4. "github.com/go-nunu/nunu-layout-advanced/internal/model"
  5. )
  6. type WebForwardingRepository interface {
  7. GetWebForwarding(ctx context.Context, id int64) (*model.WebForwarding, error)
  8. AddWebForwarding(ctx context.Context, req *model.WebForwarding) error
  9. EditWebForwarding(ctx context.Context, req *model.WebForwarding) error
  10. DeleteWebForwarding(ctx context.Context, id int64) error
  11. }
  12. func NewWebForwardingRepository(
  13. repository *Repository,
  14. ) WebForwardingRepository {
  15. return &webForwardingRepository{
  16. Repository: repository,
  17. }
  18. }
  19. type webForwardingRepository struct {
  20. *Repository
  21. }
  22. func (r *webForwardingRepository) GetWebForwarding(ctx context.Context, id int64) (*model.WebForwarding, error) {
  23. var webForwarding model.WebForwarding
  24. return &webForwarding, nil
  25. }
  26. func (r *webForwardingRepository) AddWebForwarding(ctx context.Context, req *model.WebForwarding) error {
  27. if err := r.db.Create(&req).Error; err != nil {
  28. return err
  29. }
  30. return nil
  31. }
  32. func (r *webForwardingRepository) EditWebForwarding(ctx context.Context, req *model.WebForwarding) error {
  33. if err := r.db.Updates(&req).Error; err != nil {
  34. return err
  35. }
  36. return nil
  37. }
  38. func (r *webForwardingRepository) DeleteWebForwarding(ctx context.Context, id int64) error {
  39. if err := r.db.Where("id = ?", id).Delete(&model.WebForwarding{}).Error; err != nil {
  40. return err
  41. }
  42. return nil
  43. }