feat(video): add likescount and updatelikescount

This commit is contained in:
Leon
2025-12-09 21:11:29 +08:00
parent d1c0f049d6
commit 8e51de9410
6 changed files with 68 additions and 6 deletions

View File

@@ -18,6 +18,7 @@ type PublishVideoRequest struct {
Title string `json:"title"`
Description string `json:"description"`
PlayURL string `json:"play_url"`
CoverURL string `json:"cover_url"`
}
type ListByAuthorIDRequest struct {
@@ -28,6 +29,11 @@ type GetDetailRequest struct {
ID uint `json:"id"`
}
type UpdateLikesCountRequest struct {
ID uint `json:"id"`
LikesCount int64 `json:"likes_count"`
}
func (vh *VideoHandler) PublishVideo(c *gin.Context) {
var req PublishVideoRequest
if err := c.ShouldBindJSON(&req); err != nil {
@@ -50,6 +56,7 @@ func (vh *VideoHandler) PublishVideo(c *gin.Context) {
Title: req.Title,
Description: req.Description,
PlayURL: req.PlayURL,
CoverURL: req.CoverURL,
CreateTime: time.Now(),
}
if err := vh.service.Publish(c.Request.Context(), video); err != nil {
@@ -86,3 +93,16 @@ func (vh *VideoHandler) GetDetail(c *gin.Context) {
}
c.JSON(200, video)
}
func (vh *VideoHandler) UpdateLikesCount(c *gin.Context) {
var req UpdateLikesCountRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
}
if err := vh.service.UpdateLikesCount(c.Request.Context(), req.ID, req.LikesCount); err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
}
c.JSON(200, gin.H{"message": "likes count updated"})
}