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