tercul-backend/internal/data/sql/publisher_repository.go

36 lines
990 B
Go

package repositories
import (
"context"
"gorm.io/gorm"
"tercul/internal/models"
)
// PublisherRepository defines CRUD methods specific to Publisher.
type PublisherRepository interface {
BaseRepository[models.Publisher]
ListByCountryID(ctx context.Context, countryID uint) ([]models.Publisher, error)
}
type publisherRepository struct {
BaseRepository[models.Publisher]
db *gorm.DB
}
// NewPublisherRepository creates a new PublisherRepository.
func NewPublisherRepository(db *gorm.DB) PublisherRepository {
return &publisherRepository{
BaseRepository: NewBaseRepositoryImpl[models.Publisher](db),
db: db,
}
}
// ListByCountryID finds publishers by country ID
func (r *publisherRepository) ListByCountryID(ctx context.Context, countryID uint) ([]models.Publisher, error) {
var publishers []models.Publisher
if err := r.db.WithContext(ctx).Where("country_id = ?", countryID).Find(&publishers).Error; err != nil {
return nil, err
}
return publishers, nil
}