notification.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package gorm
  2. import (
  3. "github.com/porter-dev/porter/internal/models"
  4. "github.com/porter-dev/porter/internal/repository"
  5. "gorm.io/gorm"
  6. )
  7. type NotificationConfigRepository struct {
  8. db *gorm.DB
  9. }
  10. // NewNotificationConfigRepository creates a new NotificationConfigRepository
  11. func NewNotificationConfigRepository(db *gorm.DB) repository.NotificationConfigRepository {
  12. return NotificationConfigRepository{db: db}
  13. }
  14. // CreateNotificationConfig creates a new NotificationConfig
  15. func (repo NotificationConfigRepository) CreateNotificationConfig(am *models.NotificationConfig) (*models.NotificationConfig, error) {
  16. if err := repo.db.Create(am).Error; err != nil {
  17. return nil, err
  18. }
  19. return am, nil
  20. }
  21. // ReadNotificationConfig reads a NotificationConfig by ID
  22. func (repo NotificationConfigRepository) ReadNotificationConfig(id uint) (*models.NotificationConfig, error) {
  23. ret := &models.NotificationConfig{}
  24. if err := repo.db.Where("id = ?", id).First(&ret).Error; err != nil {
  25. return nil, err
  26. }
  27. return ret, nil
  28. }
  29. // UpdateNotificationConfig updates a given NotificationConfig
  30. func (repo NotificationConfigRepository) UpdateNotificationConfig(am *models.NotificationConfig) (*models.NotificationConfig, error) {
  31. if err := repo.db.Save(am).Error; err != nil {
  32. return nil, err
  33. }
  34. return am, nil
  35. }