mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 00:31:35 +00:00
- 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
58 lines
1.8 KiB
Go
58 lines
1.8 KiB
Go
package repositories
|
|
|
|
import (
|
|
"context"
|
|
"gorm.io/gorm"
|
|
"tercul/models"
|
|
)
|
|
|
|
// CollectionRepository defines CRUD methods specific to Collection.
|
|
type CollectionRepository interface {
|
|
BaseRepository[models.Collection]
|
|
ListByUserID(ctx context.Context, userID uint) ([]models.Collection, error)
|
|
ListPublic(ctx context.Context) ([]models.Collection, error)
|
|
ListByWorkID(ctx context.Context, workID uint) ([]models.Collection, error)
|
|
}
|
|
|
|
type collectionRepository struct {
|
|
BaseRepository[models.Collection]
|
|
db *gorm.DB
|
|
}
|
|
|
|
// NewCollectionRepository creates a new CollectionRepository.
|
|
func NewCollectionRepository(db *gorm.DB) CollectionRepository {
|
|
return &collectionRepository{
|
|
BaseRepository: NewBaseRepositoryImpl[models.Collection](db),
|
|
db: db,
|
|
}
|
|
}
|
|
|
|
// ListByUserID finds collections by user ID
|
|
func (r *collectionRepository) ListByUserID(ctx context.Context, userID uint) ([]models.Collection, error) {
|
|
var collections []models.Collection
|
|
if err := r.db.WithContext(ctx).Where("user_id = ?", userID).Find(&collections).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return collections, nil
|
|
}
|
|
|
|
// ListPublic finds public collections
|
|
func (r *collectionRepository) ListPublic(ctx context.Context) ([]models.Collection, error) {
|
|
var collections []models.Collection
|
|
if err := r.db.WithContext(ctx).Where("is_public = ?", true).Find(&collections).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return collections, nil
|
|
}
|
|
|
|
// ListByWorkID finds collections by work ID
|
|
func (r *collectionRepository) ListByWorkID(ctx context.Context, workID uint) ([]models.Collection, error) {
|
|
var collections []models.Collection
|
|
if err := r.db.WithContext(ctx).Joins("JOIN collection_works ON collection_works.collection_id = collections.id").
|
|
Where("collection_works.work_id = ?", workID).
|
|
Find(&collections).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return collections, nil
|
|
}
|