A community based topic aggregation platform built on atproto
1package comments
2
3import (
4 "net/http"
5
6 "Coves/internal/core/comments"
7)
8
9// ServiceAdapter adapts the core comments.Service to the handler's Service interface
10// This bridges the gap between HTTP-layer concerns (http.Request) and domain-layer concerns (context.Context)
11type ServiceAdapter struct {
12 coreService comments.Service
13}
14
15// NewServiceAdapter creates a new service adapter wrapping the core comment service
16func NewServiceAdapter(coreService comments.Service) Service {
17 return &ServiceAdapter{
18 coreService: coreService,
19 }
20}
21
22// GetComments adapts the handler request to the core service request
23// Converts handler-specific GetCommentsRequest to core GetCommentsRequest
24func (a *ServiceAdapter) GetComments(r *http.Request, req *GetCommentsRequest) (*comments.GetCommentsResponse, error) {
25 // Convert handler request to core service request
26 coreReq := &comments.GetCommentsRequest{
27 PostURI: req.PostURI,
28 Sort: req.Sort,
29 Timeframe: req.Timeframe,
30 Depth: req.Depth,
31 Limit: req.Limit,
32 Cursor: req.Cursor,
33 ViewerDID: req.ViewerDID,
34 }
35
36 // Call core service with request context
37 return a.coreService.GetComments(r.Context(), coreReq)
38}