mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 04:01:34 +00:00
Some checks failed
- Updated database models and repositories to replace uint IDs with UUIDs. - Modified test fixtures to generate and use UUIDs for authors, translations, users, and works. - Adjusted mock implementations to align with the new UUID structure. - Ensured all relevant functions and methods are updated to handle UUIDs correctly. - Added necessary imports for UUID handling in various files.
72 lines
2.1 KiB
Go
72 lines
2.1 KiB
Go
package sql
|
|
|
|
import (
|
|
"context"
|
|
"tercul/internal/domain"
|
|
"tercul/internal/platform/config"
|
|
|
|
"github.com/google/uuid"
|
|
"go.opentelemetry.io/otel"
|
|
"go.opentelemetry.io/otel/trace"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type likeRepository struct {
|
|
domain.BaseRepository[domain.Like]
|
|
db *gorm.DB
|
|
tracer trace.Tracer
|
|
}
|
|
|
|
// NewLikeRepository creates a new LikeRepository.
|
|
func NewLikeRepository(db *gorm.DB, cfg *config.Config) domain.LikeRepository {
|
|
return &likeRepository{
|
|
BaseRepository: NewBaseRepositoryImpl[domain.Like](db, cfg),
|
|
db: db,
|
|
tracer: otel.Tracer("like.repository"),
|
|
}
|
|
}
|
|
|
|
// ListByUserID finds likes by user ID
|
|
func (r *likeRepository) ListByUserID(ctx context.Context, userID uuid.UUID) ([]domain.Like, error) {
|
|
ctx, span := r.tracer.Start(ctx, "ListByUserID")
|
|
defer span.End()
|
|
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 uuid.UUID) ([]domain.Like, error) {
|
|
ctx, span := r.tracer.Start(ctx, "ListByWorkID")
|
|
defer span.End()
|
|
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 uuid.UUID) ([]domain.Like, error) {
|
|
ctx, span := r.tracer.Start(ctx, "ListByTranslationID")
|
|
defer span.End()
|
|
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 uuid.UUID) ([]domain.Like, error) {
|
|
ctx, span := r.tracer.Start(ctx, "ListByCommentID")
|
|
defer span.End()
|
|
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
|
|
}
|