mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package sql
|
|
|
|
import (
|
|
"context"
|
|
"tercul/internal/domain"
|
|
"tercul/internal/domain/like"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
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
|
|
}
|