From 39645868a20242c26d572466316d9833ef12194f Mon Sep 17 00:00:00 2001 From: Leon <147289645+LeoninCS@users.noreply.github.com> Date: Tue, 30 Dec 2025 01:27:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=BA=E7=9B=B8=E5=85=B3=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E4=BC=A0=E5=85=A5=E6=B6=88=E6=81=AF=E9=98=9F=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/internal/http/router.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/backend/internal/http/router.go b/backend/internal/http/router.go index 43be260..8581eb6 100644 --- a/backend/internal/http/router.go +++ b/backend/internal/http/router.go @@ -37,7 +37,12 @@ func SetRouter(db *gorm.DB, cache *rediscache.Client, rmq *rabbitmq.RabbitMQ) *g } // video videoRepository := video.NewVideoRepository(db) - videoService := video.NewVideoService(videoRepository, cache) + popularityMQ, err := rabbitmq.NewPopularityMQ(rmq) + if err != nil { + log.Printf("PopularityMQ init failed (mq disabled): %v", err) + popularityMQ = nil + } + videoService := video.NewVideoService(videoRepository, cache, popularityMQ) videoHandler := video.NewVideoHandler(videoService, accountService) videoGroup := r.Group("/video") { @@ -52,9 +57,14 @@ func SetRouter(db *gorm.DB, cache *rediscache.Client, rmq *rabbitmq.RabbitMQ) *g protectedVideoGroup.POST("/publish", videoHandler.PublishVideo) } // like + likeMQ, err := rabbitmq.NewLikeMQ(rmq) + if err != nil { + log.Printf("LikeMQ init failed (mq disabled): %v", err) + likeMQ = nil + } likeRepository := video.NewLikeRepository(db) - likeService := video.NewLikeService(likeRepository, videoRepository) - likeHandler := video.NewLikeHandler(likeService, videoService) + likeService := video.NewLikeService(likeRepository, videoRepository, cache, likeMQ, popularityMQ) + likeHandler := video.NewLikeHandler(likeService) likeGroup := r.Group("/like") protectedLikeGroup := likeGroup.Group("") protectedLikeGroup.Use(jwt.JWTAuth(accountRepository, cache)) @@ -66,8 +76,13 @@ func SetRouter(db *gorm.DB, cache *rediscache.Client, rmq *rabbitmq.RabbitMQ) *g } // comment commentRepository := video.NewCommentRepository(db) - commentService := video.NewCommentService(commentRepository, videoRepository) - commentHandler := video.NewCommentHandler(commentService, accountService, videoService) + commentMQ, err := rabbitmq.NewCommentMQ(rmq) + if err != nil { + log.Printf("CommentMQ init failed (mq disabled): %v", err) + commentMQ = nil + } + commentService := video.NewCommentService(commentRepository, videoRepository, cache, commentMQ, popularityMQ) + commentHandler := video.NewCommentHandler(commentService, accountService) commentGroup := r.Group("/comment") { commentGroup.POST("/listAll", commentHandler.GetAllComments)