A social knowledge tool for researchers built on ATProto
at main 47 lines 1.6 kB view raw
1import { Response } from 'express'; 2import { z } from 'zod'; 3import { GetGlobalFeedUseCase } from '../../../application/useCases/queries/GetGlobalFeedUseCase'; 4import { Controller } from 'src/shared/infrastructure/http/Controller'; 5import { AuthenticatedRequest } from 'src/shared/infrastructure/http/middleware/AuthMiddleware'; 6import { GetGlobalFeedResponse } from '@semble/types'; 7 8// Zod schema for request validation 9const querySchema = z.object({ 10 page: z.coerce.number().int().positive().optional(), 11 limit: z.coerce.number().int().positive().max(100).optional(), 12 beforeActivityId: z.string().optional(), 13}); 14 15export class GetGlobalFeedController extends Controller { 16 constructor(private getGlobalFeedUseCase: GetGlobalFeedUseCase) { 17 super(); 18 } 19 20 async executeImpl(req: AuthenticatedRequest, res: Response): Promise<any> { 21 try { 22 // Validate request with Zod 23 const validation = querySchema.safeParse(req.query); 24 if (!validation.success) { 25 return this.badRequest(res, JSON.stringify(validation.error.format())); 26 } 27 28 const params = validation.data; 29 const callerDid = req.did; 30 31 const result = await this.getGlobalFeedUseCase.execute({ 32 callingUserId: callerDid, 33 page: params.page || 1, 34 limit: params.limit || 20, 35 beforeActivityId: params.beforeActivityId, 36 }); 37 38 if (result.isErr()) { 39 return this.fail(res, result.error.message); 40 } 41 42 return this.ok<GetGlobalFeedResponse>(res, result.value); 43 } catch (error) { 44 return this.fail(res, 'An unexpected error occurred'); 45 } 46 } 47}