feat: add post like
This commit is contained in:
@@ -162,7 +162,10 @@ func (s *Server) initAuth(cfg *config.Config, logger *zap.Logger) {
|
||||
postRepo := repository.NewPostRepo(s.pg)
|
||||
bookmarkRepo := repository.NewBookmarkRepo(s.pg)
|
||||
collectionRepo := repository.NewCollectionRepo(s.pg)
|
||||
postSvc := service.NewPostService(postRepo, r2)
|
||||
// Likes: membership in Postgres, count delta batched through Redis
|
||||
// (s.redis may be nil — LikeRepo then applies counts directly).
|
||||
likeRepo := repository.NewLikeRepo(s.pg, s.redis, logger)
|
||||
postSvc := service.NewPostService(postRepo, r2, likeRepo)
|
||||
bookmarkSvc := service.NewBookmarkService(userRepo, bookmarkRepo)
|
||||
collectionSvc := service.NewCollectionService(userRepo, collectionRepo, postRepo, r2)
|
||||
|
||||
@@ -210,6 +213,9 @@ func (s *Server) initAuth(cfg *config.Config, logger *zap.Logger) {
|
||||
pushSender := service.NewPushSender(pushRepo, cfg.VAPIDPublicKey, cfg.VAPIDPrivateKey, cfg.VAPIDSubject, logger)
|
||||
s.pushH = handler.NewPushHandler(pushSender, pushRepo)
|
||||
notifSvc := service.NewNotificationService(notifRepo, userRepo, mail, rtClient, pushSender, logger, cfg.FrontendURL)
|
||||
// Wire the notification seam into the post service so a new like notifies
|
||||
// the author (push + realtime; not the liker themselves).
|
||||
postSvc.SetNotifier(notifSvc)
|
||||
|
||||
// Sādhana reminders: a background worker nudges users (email + push +
|
||||
// websocket) to chant / post a quote at their local time. Shares the
|
||||
@@ -223,11 +229,15 @@ func (s *Server) initAuth(cfg *config.Config, logger *zap.Logger) {
|
||||
}
|
||||
worker.NewReminderWorker(reminderSvc, logger).Run(wctx)
|
||||
|
||||
// Likes worker: folds the pending Redis like-deltas into posts.likes_count
|
||||
// every 15 minutes (no-op when Redis is unavailable).
|
||||
worker.NewLikesWorker(likeRepo, logger).Run(wctx)
|
||||
|
||||
graphSvc := service.NewSocialGraphService(followRepo, blockRepo, reportRepo, postRepo, userRepo, notifSvc, mail, cfg.FeedbackAdminEmails, logger)
|
||||
s.relationH = handler.NewRelationshipHandler(graphSvc)
|
||||
s.notificationH = handler.NewNotificationHandler(notifSvc)
|
||||
s.postH = handler.NewPostHandler(postSvc, graphSvc)
|
||||
s.profileH = handler.NewProfileHandler(userRepo, postRepo, collectionRepo, graphSvc)
|
||||
s.profileH = handler.NewProfileHandler(userRepo, postRepo, collectionRepo, graphSvc, likeRepo)
|
||||
|
||||
// Sādhana streak: daily chanting log + the growing-plant state. Reads
|
||||
// the chanting half from sadhna_logs and the posting half from the
|
||||
@@ -631,6 +641,8 @@ func (s *Server) setupRouter() {
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(middleware.OptionalAuth(s.authIssuer, s.userRepo))
|
||||
r.Get("/{id}", s.postH.Get)
|
||||
// Paginated "liked by" list — public, like the count itself.
|
||||
r.Get("/{id}/likes", s.postH.ListLikes)
|
||||
})
|
||||
// Protected — create / delete / image presign / "my posts" /
|
||||
// reshare actions.
|
||||
@@ -646,6 +658,10 @@ func (s *Server) setupRouter() {
|
||||
// double-clicks don't 4xx.
|
||||
r.Post("/{id}/reshare", s.postH.Reshare)
|
||||
r.Delete("/{id}/reshare", s.postH.Unreshare)
|
||||
// Like / unlike — idempotent; membership is written now, the
|
||||
// count is batched into likes_count via Redis.
|
||||
r.Post("/{id}/like", s.postH.Like)
|
||||
r.Delete("/{id}/like", s.postH.Unlike)
|
||||
// Report a post (category + optional reason) → admin email.
|
||||
r.Post("/{id}/report", s.postH.Report)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user