tercul-backend/repositories/edition_repository.go
Damir Mukimov 4957117cb6 Initial commit: Tercul Go project with comprehensive architecture
- Core Go application with GraphQL API using gqlgen
- Comprehensive data models for literary works, authors, translations
- Repository pattern with caching layer
- Authentication and authorization system
- Linguistics analysis capabilities with multiple adapters
- Vector search integration with Weaviate
- Docker containerization support
- Python data migration and analysis scripts
- Clean architecture with proper separation of concerns
- Production-ready configuration and middleware
- Proper .gitignore excluding vendor/, database files, and build artifacts
2025-08-13 07:42:32 +02:00

50 lines
1.4 KiB
Go

package repositories
import (
"context"
"errors"
"gorm.io/gorm"
"tercul/models"
)
// EditionRepository defines CRUD methods specific to Edition.
type EditionRepository interface {
BaseRepository[models.Edition]
ListByBookID(ctx context.Context, bookID uint) ([]models.Edition, error)
FindByISBN(ctx context.Context, isbn string) (*models.Edition, error)
}
type editionRepository struct {
BaseRepository[models.Edition]
db *gorm.DB
}
// NewEditionRepository creates a new EditionRepository.
func NewEditionRepository(db *gorm.DB) EditionRepository {
return &editionRepository{
BaseRepository: NewBaseRepositoryImpl[models.Edition](db),
db: db,
}
}
// ListByBookID finds editions by book ID
func (r *editionRepository) ListByBookID(ctx context.Context, bookID uint) ([]models.Edition, error) {
var editions []models.Edition
if err := r.db.WithContext(ctx).Where("book_id = ?", bookID).Find(&editions).Error; err != nil {
return nil, err
}
return editions, nil
}
// FindByISBN finds an edition by ISBN
func (r *editionRepository) FindByISBN(ctx context.Context, isbn string) (*models.Edition, error) {
var edition models.Edition
if err := r.db.WithContext(ctx).Where("isbn = ?", isbn).First(&edition).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, ErrEntityNotFound
}
return nil, err
}
return &edition, nil
}