notify_repository.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package repositories
  2. import (
  3. "context"
  4. "gorm.io/gorm"
  5. "sikey.com/websocket/models"
  6. )
  7. type NotifyRepository interface {
  8. Create(ctx context.Context, n *models.Notify) error
  9. Find(ctx context.Context, id int64) (*models.Notify, error)
  10. Save(ctx context.Context, notify *models.Notify) error
  11. }
  12. func NewNotifyRepository(source *gorm.DB) NotifyRepository {
  13. return &notifyRepository{source: source}
  14. }
  15. type notifyRepository struct {
  16. source *gorm.DB
  17. }
  18. // Save implements NotifyRepository.
  19. func (repo *notifyRepository) Save(ctx context.Context, notify *models.Notify) error {
  20. return repo.source.WithContext(ctx).Save(notify).Error
  21. }
  22. // Find implements NotifyRepository.
  23. func (repo *notifyRepository) Find(ctx context.Context, id int64) (*models.Notify, error) {
  24. var err error
  25. var notify models.Notify
  26. err = repo.source.WithContext(ctx).Where(&models.Notify{Id: id}).First(&notify).Error
  27. return result(notify, err)
  28. }
  29. // Create implements NotifyRepository.
  30. func (repo *notifyRepository) Create(ctx context.Context, n *models.Notify) error {
  31. return repo.source.WithContext(ctx).Model(&models.Notify{}).Create(n).Error
  32. }