feat: 帖子收藏与用户关注

- 新增收藏功能:favorite 服务与 handler、FavoriteButton 组件
- 新增关注功能:follow 服务与 handler、FollowButton 组件
- 用户主页适配关注/粉丝与收藏展示
- flash 消息工具、广告与侧边栏组件微调
This commit is contained in:
2026-09-26 03:02:40 +08:00
parent 31f5360c26
commit d7c6b3a961
40 changed files with 1528 additions and 268 deletions

View File

@@ -66,6 +66,8 @@ func Setup(cfg *config.Config) (*gin.Engine, error) {
commentSvc := service.NewCommentService(model.DB).WithSetting(settingSvc)
likeSvc := service.NewLikeService(model.DB)
notifSvc := service.NewNotificationService(model.DB)
favoriteSvc := service.NewFavoriteService(model.DB).WithPosts(postSvc)
followSvc := service.NewFollowService(model.DB).WithNotification(notifSvc)
overviewSvc := service.NewOverviewService(model.DB)
checkinSvc := service.NewCheckinService(model.DB).WithSetting(settingSvc)
announcementSvc := service.NewAnnouncementService(model.DB)
@@ -108,6 +110,8 @@ func Setup(cfg *config.Config) (*gin.Engine, error) {
Post: postSvc,
Comment: commentSvc,
Like: likeSvc,
Favorite: favoriteSvc,
Follow: followSvc,
Notification: notifSvc,
OverviewSvc: overviewSvc,
Checkin: checkinSvc,
@@ -170,8 +174,11 @@ func Setup(cfg *config.Config) (*gin.Engine, error) {
pubAPI.POST("/posts/:id/unlock-password", middleware.CSRFMiddleware(), middleware.RateLimitMiddleware(limiter, service.RateHidePassword), h.UnlockPostPassword)
pubAPI.GET("/posts/:id/attachments/:aid/download", h.DownloadPostAttachment)
pubAPI.GET("/posts/:id/comments", h.PostComments)
pubAPI.GET("/posts/:id/comments/:cid", h.CommentLocation)
pubAPI.GET("/users/:id", h.UserProfile)
pubAPI.GET("/users/:id/comments", h.UserComments)
pubAPI.GET("/users/:id/favorites", h.UserFavorites)
pubAPI.GET("/users/:id/following", h.UserFollowing)
pubAPI.GET("/announcements", h.AnnouncementsList)
pubAPI.GET("/announcements/:id", h.AnnouncementDetail)
pubAPI.GET("/pages", h.SitePagesList)
@@ -220,6 +227,8 @@ func Setup(cfg *config.Config) (*gin.Engine, error) {
api.PUT("/posts/:id/recommend", h.ToggleRecommend)
api.PUT("/posts/:id/lock", h.TogglePostLock)
api.POST("/posts/:id/like", h.ToggleLike)
api.POST("/posts/:id/favorite", middleware.StaffExempt(middleware.RateLimitUserMiddleware(limiter, service.RateInteract)), h.ToggleFavorite)
api.POST("/users/:id/follow", middleware.StaffExempt(middleware.RateLimitUserMiddleware(limiter, service.RateInteract)), h.ToggleFollow)
api.POST("/posts/:id/comments", middleware.StaffExempt(middleware.RateLimitMiddleware(limiter, service.RateComment)), h.CreateComment)
api.PUT("/posts/:id/comments/:cid", middleware.StaffExempt(middleware.RateLimitMiddleware(limiter, service.RateComment)), h.UpdateComment)
api.DELETE("/posts/:id/comments/:cid", h.DeleteComment)