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