tercul-backend/repositories/edge_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

36 lines
968 B
Go

package repositories
import (
"context"
"gorm.io/gorm"
"tercul/models"
)
// EdgeRepository defines CRUD operations for the polymorphic edge table.
type EdgeRepository interface {
BaseRepository[models.Edge]
ListBySource(ctx context.Context, sourceTable string, sourceID uint) ([]models.Edge, error)
}
type edgeRepository struct {
BaseRepository[models.Edge]
db *gorm.DB
}
// NewEdgeRepository creates a new EdgeRepository.
func NewEdgeRepository(db *gorm.DB) EdgeRepository {
return &edgeRepository{
BaseRepository: NewBaseRepositoryImpl[models.Edge](db),
db: db,
}
}
// ListBySource finds edges by source table and ID
func (r *edgeRepository) ListBySource(ctx context.Context, sourceTable string, sourceID uint) ([]models.Edge, error) {
var edges []models.Edge
if err := r.db.WithContext(ctx).Where("source_table = ? AND source_id = ?", sourceTable, sourceID).Find(&edges).Error; err != nil {
return nil, err
}
return edges, nil
}