diff --git a/cmd/server/main.go b/cmd/server/main.go --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -408,10 +408,11 @@ // non-deleted subjects. This avoids race conditions and eventual consistency issues. voteService := votes.NewService(voteRepo, oauthClient, oauthStore, voteCache, nil) log.Println("✅ Vote service initialized (with OAuth authentication and vote cache)") - // Initialize comment service (for query API) + // Initialize comment service (for query and write APIs) // Requires user and community repos for proper author/community hydration per lexicon - commentService := comments.NewCommentService(commentRepo, userRepo, postRepo, communityRepo) - log.Println("✅ Comment service initialized (with author/community hydration)") + // OAuth client and store are needed for write operations (create, update, delete) + commentService := comments.NewCommentService(commentRepo, userRepo, postRepo, communityRepo, oauthClient, oauthStore, nil) + log.Println("✅ Comment service initialized (with author/community hydration and write support)") // Initialize feed service feedRepo := postgresRepo.NewCommunityFeedRepository(db, cursorSecret) @@ -528,6 +529,13 @@ log.Println("Post XRPC endpoints registered with OAuth authentication") routes.RegisterVoteRoutes(r, voteService, authMiddleware) log.Println("Vote XRPC endpoints registered with OAuth authentication") + + // Register comment write routes (create, update, delete) + routes.RegisterCommentRoutes(r, commentService, authMiddleware) + log.Println("Comment write XRPC endpoints registered") + log.Println(" - POST /xrpc/social.coves.community.comment.create") + log.Println(" - POST /xrpc/social.coves.community.comment.update") + log.Println(" - POST /xrpc/social.coves.community.comment.delete") routes.RegisterCommunityFeedRoutes(r, feedService, voteService, authMiddleware) log.Println("Feed XRPC endpoints registered (public with optional auth for viewer vote state)") diff --git a/internal/api/routes/comment.go b/internal/api/routes/comment.go new file mode 100644 --- /dev/null +++ b/internal/api/routes/comment.go @@ -0,0 +1,35 @@ +package routes + +import ( + "Coves/internal/api/handlers/comments" + "Coves/internal/api/middleware" + commentsCore "Coves/internal/core/comments" + + "github.com/go-chi/chi/v5" +) + +// RegisterCommentRoutes registers comment-related XRPC endpoints on the router +// Implements social.coves.community.comment.* lexicon endpoints +// All write operations (create, update, delete) require authentication +func RegisterCommentRoutes(r chi.Router, service commentsCore.Service, authMiddleware *middleware.OAuthAuthMiddleware) { + // Initialize handlers + createHandler := comments.NewCreateCommentHandler(service) + updateHandler := comments.NewUpdateCommentHandler(service) + deleteHandler := comments.NewDeleteCommentHandler(service) + + // Procedure endpoints (POST) - require authentication + // social.coves.community.comment.create - create a new comment on a post or another comment + r.With(authMiddleware.RequireAuth).Post( + "/xrpc/social.coves.community.comment.create", + createHandler.HandleCreate) + + // social.coves.community.comment.update - update an existing comment's content + r.With(authMiddleware.RequireAuth).Post( + "/xrpc/social.coves.community.comment.update", + updateHandler.HandleUpdate) + + // social.coves.community.comment.delete - soft delete a comment + r.With(authMiddleware.RequireAuth).Post( + "/xrpc/social.coves.community.comment.delete", + deleteHandler.HandleDelete) +}