12345678910111213141516171819202122232425262728293031323334353637383940 |
- package repositories
- import (
- "context"
- "gorm.io/gorm"
- "sikey.com/websocket/models"
- )
- type NotifyRepository interface {
- Create(ctx context.Context, n *models.Notify) error
- Find(ctx context.Context, id int64) (*models.Notify, error)
- Save(ctx context.Context, notify *models.Notify) error
- }
- func NewNotifyRepository(source *gorm.DB) NotifyRepository {
- return ¬ifyRepository{source: source}
- }
- type notifyRepository struct {
- source *gorm.DB
- }
- // Save implements NotifyRepository.
- func (repo *notifyRepository) Save(ctx context.Context, notify *models.Notify) error {
- return repo.source.WithContext(ctx).Save(notify).Error
- }
- // Find implements NotifyRepository.
- func (repo *notifyRepository) Find(ctx context.Context, id int64) (*models.Notify, error) {
- var err error
- var notify models.Notify
- err = repo.source.WithContext(ctx).Where(&models.Notify{Id: id}).First(¬ify).Error
- return result(notify, err)
- }
- // Create implements NotifyRepository.
- func (repo *notifyRepository) Create(ctx context.Context, n *models.Notify) error {
- return repo.source.WithContext(ctx).Model(&models.Notify{}).Create(n).Error
- }
|