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