feat: 添加了列出点赞视频的功能
This commit is contained in:
@@ -89,3 +89,18 @@ func (lh *LikeHandler) IsLiked(c *gin.Context) {
|
||||
}
|
||||
c.JSON(200, gin.H{"is_liked": isLiked})
|
||||
}
|
||||
|
||||
func (lh *LikeHandler) ListMyLikedVideos(c *gin.Context) {
|
||||
accountID, err := middleware.GetAccountID(c)
|
||||
if err != nil {
|
||||
c.JSON(400, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
videos, err := lh.service.ListLikedVideos(c.Request.Context(), accountID)
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(200, videos)
|
||||
}
|
||||
|
||||
@@ -54,3 +54,20 @@ func (r *LikeRepository) BatchGetLiked(ctx context.Context, videoIDs []uint, acc
|
||||
}
|
||||
return likeMap, nil
|
||||
}
|
||||
|
||||
func (r *LikeRepository) ListLikedVideos(ctx context.Context, accountID uint) ([]Video, error) {
|
||||
var videos []Video
|
||||
if accountID == 0 {
|
||||
return videos, nil
|
||||
}
|
||||
err := r.db.WithContext(ctx).
|
||||
Model(&Video{}).
|
||||
Joins("JOIN likes ON likes.video_id = videos.id").
|
||||
Where("likes.account_id = ?", accountID).
|
||||
Order("likes.created_at desc").
|
||||
Find(&videos).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return videos, nil
|
||||
}
|
||||
|
||||
@@ -64,3 +64,7 @@ func (s *LikeService) Unlike(ctx context.Context, like *Like) error {
|
||||
func (s *LikeService) IsLiked(ctx context.Context, videoID, accountID uint) (bool, error) {
|
||||
return s.repo.IsLiked(ctx, videoID, accountID)
|
||||
}
|
||||
|
||||
func (s *LikeService) ListLikedVideos(ctx context.Context, accountID uint) ([]Video, error) {
|
||||
return s.repo.ListLikedVideos(ctx, accountID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user