A community based topic aggregation platform built on atproto

feat(comments): add routes and wire up comment service

- Add RegisterCommentRoutes for comment write XRPC endpoints
- Wire comment service with OAuth dependencies in main.go
- All write endpoints require OAuth authentication middleware

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

Changed files
+46 -3
cmd
server
internal
api
routes
+11 -3
cmd/server/main.go
···
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)
// 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)")
// Initialize feed service
feedRepo := postgresRepo.NewCommunityFeedRepository(db, cursorSecret)
···
routes.RegisterVoteRoutes(r, voteService, authMiddleware)
log.Println("Vote XRPC endpoints registered with OAuth authentication")
routes.RegisterCommunityFeedRoutes(r, feedService, voteService, authMiddleware)
log.Println("Feed XRPC endpoints registered (public with optional auth for viewer vote state)")
···
voteService := votes.NewService(voteRepo, oauthClient, oauthStore, voteCache, nil)
log.Println("✅ Vote service initialized (with OAuth authentication and vote cache)")
+
// Initialize comment service (for query and write APIs)
// Requires user and community repos for proper author/community hydration per lexicon
+
// 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)
···
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)")
+35
internal/api/routes/comment.go
···
···
+
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)
+
}