feat:添加热榜功能并添加了增加热度的方法。

This commit is contained in:
Leon
2025-12-26 22:49:17 +08:00
parent 14a905e194
commit 328fae5f07
12 changed files with 327 additions and 10 deletions

View File

@@ -6,8 +6,13 @@ import (
"github.com/gin-gonic/gin"
)
func NewLikeHandler(service *LikeService) *LikeHandler {
return &LikeHandler{service: service}
type LikeHandler struct {
service *LikeService
videoService *VideoService
}
func NewLikeHandler(service *LikeService, videoService *VideoService) *LikeHandler {
return &LikeHandler{service: service, videoService: videoService}
}
func (lh *LikeHandler) Like(c *gin.Context) {
@@ -35,6 +40,10 @@ func (lh *LikeHandler) Like(c *gin.Context) {
c.JSON(500, gin.H{"error": err.Error()})
return
}
if err := lh.videoService.UpdatePopularity(c.Request.Context(), req.VideoID, 1); err != nil {
c.JSON(500, gin.H{"error": err.Error()})
return
}
c.JSON(200, gin.H{"message": "like success"})
}
@@ -63,6 +72,10 @@ func (lh *LikeHandler) Unlike(c *gin.Context) {
c.JSON(500, gin.H{"error": err.Error()})
return
}
if err := lh.videoService.UpdatePopularity(c.Request.Context(), req.VideoID, -1); err != nil {
c.JSON(500, gin.H{"error": err.Error()})
return
}
c.JSON(200, gin.H{"message": "unlike success"})
}