mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +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
66 lines
2.0 KiB
Go
66 lines
2.0 KiB
Go
package repositories
|
|
|
|
import (
|
|
"context"
|
|
"gorm.io/gorm"
|
|
"tercul/models"
|
|
)
|
|
|
|
// LikeRepository defines CRUD methods specific to Like.
|
|
type LikeRepository interface {
|
|
BaseRepository[models.Like]
|
|
ListByUserID(ctx context.Context, userID uint) ([]models.Like, error)
|
|
ListByWorkID(ctx context.Context, workID uint) ([]models.Like, error)
|
|
ListByTranslationID(ctx context.Context, translationID uint) ([]models.Like, error)
|
|
ListByCommentID(ctx context.Context, commentID uint) ([]models.Like, error)
|
|
}
|
|
|
|
type likeRepository struct {
|
|
BaseRepository[models.Like]
|
|
db *gorm.DB
|
|
}
|
|
|
|
// NewLikeRepository creates a new LikeRepository.
|
|
func NewLikeRepository(db *gorm.DB) LikeRepository {
|
|
return &likeRepository{
|
|
BaseRepository: NewBaseRepositoryImpl[models.Like](db),
|
|
db: db,
|
|
}
|
|
}
|
|
|
|
// ListByUserID finds likes by user ID
|
|
func (r *likeRepository) ListByUserID(ctx context.Context, userID uint) ([]models.Like, error) {
|
|
var likes []models.Like
|
|
if err := r.db.WithContext(ctx).Where("user_id = ?", userID).Find(&likes).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return likes, nil
|
|
}
|
|
|
|
// ListByWorkID finds likes by work ID
|
|
func (r *likeRepository) ListByWorkID(ctx context.Context, workID uint) ([]models.Like, error) {
|
|
var likes []models.Like
|
|
if err := r.db.WithContext(ctx).Where("work_id = ?", workID).Find(&likes).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return likes, nil
|
|
}
|
|
|
|
// ListByTranslationID finds likes by translation ID
|
|
func (r *likeRepository) ListByTranslationID(ctx context.Context, translationID uint) ([]models.Like, error) {
|
|
var likes []models.Like
|
|
if err := r.db.WithContext(ctx).Where("translation_id = ?", translationID).Find(&likes).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return likes, nil
|
|
}
|
|
|
|
// ListByCommentID finds likes by comment ID
|
|
func (r *likeRepository) ListByCommentID(ctx context.Context, commentID uint) ([]models.Like, error) {
|
|
var likes []models.Like
|
|
if err := r.db.WithContext(ctx).Where("comment_id = ?", commentID).Find(&likes).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return likes, nil
|
|
}
|