A community based topic aggregation platform built on atproto
1package community
2
3import (
4 "Coves/internal/core/communities"
5 "encoding/json"
6 "net/http"
7)
8
9// GetHandler handles community retrieval
10type GetHandler struct {
11 service communities.Service
12}
13
14// NewGetHandler creates a new get handler
15func NewGetHandler(service communities.Service) *GetHandler {
16 return &GetHandler{
17 service: service,
18 }
19}
20
21// HandleGet retrieves a community by DID or handle
22// GET /xrpc/social.coves.community.get?community={did_or_handle}
23func (h *GetHandler) HandleGet(w http.ResponseWriter, r *http.Request) {
24 if r.Method != http.MethodGet {
25 http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
26 return
27 }
28
29 // Get community identifier from query params
30 communityID := r.URL.Query().Get("community")
31 if communityID == "" {
32 writeError(w, http.StatusBadRequest, "InvalidRequest", "community parameter is required")
33 return
34 }
35
36 // Get community from AppView DB
37 community, err := h.service.GetCommunity(r.Context(), communityID)
38 if err != nil {
39 handleServiceError(w, err)
40 return
41 }
42
43 // Return community data
44 w.Header().Set("Content-Type", "application/json")
45 w.WriteHeader(http.StatusOK)
46 if err := json.NewEncoder(w).Encode(community); err != nil {
47 // Log encoding errors but don't return error response (headers already sent)
48 // This follows Go's standard practice for HTTP handlers
49 _ = err
50 }
51}