tercul-backend/internal/data/sql/like_repository.go
google-labs-jules[bot] 8797cec718 Refactor: In-progress refactoring to fix build.
This commit includes the following changes:
- Refactored all data repositories in `internal/data/sql/` to use a consistent `sql` package and to align with the new `domain` models.
- Fixed the GraphQL structure by moving the server creation logic from `internal/app` to `cmd/api`, which resolved an import cycle.
- Corrected numerous incorrect import paths for packages like `graph`, `linguistics`, `syncjob`, and the legacy `models` package.
- Resolved several package and function redeclaration errors.
- Removed legacy migration code.
2025-09-05 15:11:30 +00:00

57 lines
1.6 KiB
Go

package sql
import (
"context"
"gorm.io/gorm"
"tercul/internal/domain/like"
)
type likeRepository struct {
domain.BaseRepository[domain.Like]
db *gorm.DB
}
// NewLikeRepository creates a new LikeRepository.
func NewLikeRepository(db *gorm.DB) like.LikeRepository {
return &likeRepository{
BaseRepository: NewBaseRepositoryImpl[domain.Like](db),
db: db,
}
}
// ListByUserID finds likes by user ID
func (r *likeRepository) ListByUserID(ctx context.Context, userID uint) ([]domain.Like, error) {
var likes []domain.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) ([]domain.Like, error) {
var likes []domain.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) ([]domain.Like, error) {
var likes []domain.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) ([]domain.Like, error) {
var likes []domain.Like
if err := r.db.WithContext(ctx).Where("comment_id = ?", commentID).Find(&likes).Error; err != nil {
return nil, err
}
return likes, nil
}