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, authMiddleware *middleware.AtProtoAuthMiddleware, 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)
20 searchHandler := community.NewSearchHandler(service)
21 subscribeHandler := community.NewSubscribeHandler(service)
22 blockHandler := community.NewBlockHandler(service)
23
24 // Query endpoints (GET) - public access
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 r.Get("/xrpc/social.coves.community.list", listHandler.HandleList)
30
31 // social.coves.community.search - search communities
32 r.Get("/xrpc/social.coves.community.search", searchHandler.HandleSearch)
33
34 // Procedure endpoints (POST) - require authentication
35 // social.coves.community.create - create a new community
36 r.With(authMiddleware.RequireAuth).Post("/xrpc/social.coves.community.create", createHandler.HandleCreate)
37
38 // social.coves.community.update - update an existing community
39 r.With(authMiddleware.RequireAuth).Post("/xrpc/social.coves.community.update", updateHandler.HandleUpdate)
40
41 // social.coves.community.subscribe - subscribe to a community
42 r.With(authMiddleware.RequireAuth).Post("/xrpc/social.coves.community.subscribe", subscribeHandler.HandleSubscribe)
43
44 // social.coves.community.unsubscribe - unsubscribe from a community
45 r.With(authMiddleware.RequireAuth).Post("/xrpc/social.coves.community.unsubscribe", subscribeHandler.HandleUnsubscribe)
46
47 // social.coves.community.blockCommunity - block a community
48 r.With(authMiddleware.RequireAuth).Post("/xrpc/social.coves.community.blockCommunity", blockHandler.HandleBlock)
49
50 // social.coves.community.unblockCommunity - unblock a community
51 r.With(authMiddleware.RequireAuth).Post("/xrpc/social.coves.community.unblockCommunity", blockHandler.HandleUnblock)
52
53 // TODO: Add delete handler when implemented
54 // r.With(authMiddleware.RequireAuth).Post("/xrpc/social.coves.community.delete", deleteHandler.HandleDelete)
55}