mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 00:31:35 +00:00
36 lines
977 B
Go
36 lines
977 B
Go
package repositories
|
|
|
|
import (
|
|
"context"
|
|
"gorm.io/gorm"
|
|
"tercul/internal/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
|
|
}
|