A social knowledge tool for researchers built on ATProto
1import { Controller } from '../../../../../shared/infrastructure/http/Controller';
2import { Response } from 'express';
3import { CreateCollectionUseCase } from '../../../application/useCases/commands/CreateCollectionUseCase';
4import { AuthenticatedRequest } from '../../../../../shared/infrastructure/http/middleware/AuthMiddleware';
5
6export class CreateCollectionController extends Controller {
7 constructor(private createCollectionUseCase: CreateCollectionUseCase) {
8 super();
9 }
10
11 async executeImpl(req: AuthenticatedRequest, res: Response): Promise<any> {
12 try {
13 const { name, description } = req.body;
14 const curatorId = req.did;
15
16 if (!curatorId) {
17 return this.unauthorized(res);
18 }
19
20 if (!name) {
21 return this.badRequest(res, 'Collection name is required');
22 }
23
24 const result = await this.createCollectionUseCase.execute({
25 name,
26 description,
27 curatorId,
28 });
29
30 if (result.isErr()) {
31 return this.fail(res, result.error);
32 }
33
34 return this.ok(res, result.value);
35 } catch (error: any) {
36 return this.fail(res, error);
37 }
38 }
39}