A community based topic aggregation platform built on atproto
1package routes
2
3import (
4 "Coves/internal/api/handlers/community"
5 "Coves/internal/api/middleware"
6 "Coves/internal/core/communities"
7
8 "github.com/go-chi/chi/v5"
9)
10
11// RegisterCommunityRoutes registers community-related XRPC endpoints on the router
12// Implements social.coves.community.* lexicon endpoints
13// allowedCommunityCreators restricts who can create communities. If empty, anyone can create.
14func RegisterCommunityRoutes(r chi.Router, service communities.Service, repo communities.Repository, authMiddleware *middleware.OAuthAuthMiddleware, allowedCommunityCreators []string) {
15 // Initialize handlers
16 createHandler := community.NewCreateHandler(service, allowedCommunityCreators)
17 getHandler := community.NewGetHandler(service)
18 updateHandler := community.NewUpdateHandler(service)
19 listHandler := community.NewListHandler(service, repo)
20 searchHandler := community.NewSearchHandler(service)
21 subscribeHandler := community.NewSubscribeHandler(service)
22 blockHandler := community.NewBlockHandler(service)
23
24 // Query endpoints (GET) - public access, optional auth for viewer state
25 // social.coves.community.get - get a single community by identifier
26 r.Get("/xrpc/social.coves.community.get", getHandler.HandleGet)
27
28 // social.coves.community.list - list communities with filters
29 // Uses OptionalAuth to populate viewer.subscribed when authenticated
30 r.With(authMiddleware.OptionalAuth).Get("/xrpc/social.coves.community.list", listHandler.HandleList)
31
32 // social.coves.community.search - search communities
33 r.Get("/xrpc/social.coves.community.search", searchHandler.HandleSearch)
34
35 // Procedure endpoints (POST) - require authentication
36 // social.coves.community.create - create a new community
37 r.With(authMiddleware.RequireAuth).Post("/xrpc/social.coves.community.create", createHandler.HandleCreate)
38
39 // social.coves.community.update - update an existing community
40 r.With(authMiddleware.RequireAuth).Post("/xrpc/social.coves.community.update", updateHandler.HandleUpdate)
41
42 // social.coves.community.subscribe - subscribe to a community
43 r.With(authMiddleware.RequireAuth).Post("/xrpc/social.coves.community.subscribe", subscribeHandler.HandleSubscribe)
44
45 // social.coves.community.unsubscribe - unsubscribe from a community
46 r.With(authMiddleware.RequireAuth).Post("/xrpc/social.coves.community.unsubscribe", subscribeHandler.HandleUnsubscribe)
47
48 // social.coves.community.blockCommunity - block a community
49 r.With(authMiddleware.RequireAuth).Post("/xrpc/social.coves.community.blockCommunity", blockHandler.HandleBlock)
50
51 // social.coves.community.unblockCommunity - unblock a community
52 r.With(authMiddleware.RequireAuth).Post("/xrpc/social.coves.community.unblockCommunity", blockHandler.HandleUnblock)
53
54 // TODO: Add delete handler when implemented
55 // r.With(authMiddleware.RequireAuth).Post("/xrpc/social.coves.community.delete", deleteHandler.HandleDelete)
56}