A social knowledge tool for researchers built on ATProto
1import { Controller } from '../../../../../shared/infrastructure/http/Controller';
2import { Response } from 'express';
3import { GetCollectionPageUseCase } from '../../../application/useCases/queries/GetCollectionPageUseCase';
4import { AuthenticatedRequest } from '../../../../../shared/infrastructure/http/middleware/AuthMiddleware';
5import { CardSortField, SortOrder } from '../../../domain/ICardQueryRepository';
6
7export class GetCollectionPageController extends Controller {
8 constructor(private getCollectionPageUseCase: GetCollectionPageUseCase) {
9 super();
10 }
11
12 async executeImpl(req: AuthenticatedRequest, res: Response): Promise<any> {
13 try {
14 const { collectionId } = req.params;
15 const { page, limit, sortBy, sortOrder } = req.query;
16 const callerDid = req.did;
17
18 if (!collectionId) {
19 return this.badRequest(res, 'Collection ID is required');
20 }
21
22 const result = await this.getCollectionPageUseCase.execute({
23 collectionId,
24 callerDid,
25 page: page ? parseInt(page as string) : undefined,
26 limit: limit ? parseInt(limit as string) : undefined,
27 sortBy: sortBy as CardSortField,
28 sortOrder: sortOrder as SortOrder,
29 });
30
31 if (result.isErr()) {
32 return this.fail(res, result.error);
33 }
34
35 return this.ok(res, result.value);
36 } catch (error: any) {
37 return this.fail(res, error);
38 }
39 }
40}