A social knowledge tool for researchers built on ATProto
at development 1.2 kB view raw
1import { Controller } from '../../../../../shared/infrastructure/http/Controller'; 2import { Response } from 'express'; 3import { AddUrlToLibraryUseCase } from '../../../application/useCases/commands/AddUrlToLibraryUseCase'; 4import { AuthenticatedRequest } from '../../../../../shared/infrastructure/http/middleware/AuthMiddleware'; 5 6export class AddUrlToLibraryController extends Controller { 7 constructor(private addUrlToLibraryUseCase: AddUrlToLibraryUseCase) { 8 super(); 9 } 10 11 async executeImpl(req: AuthenticatedRequest, res: Response): Promise<any> { 12 try { 13 const { url, note, collectionIds } = req.body; 14 const curatorId = req.did; 15 16 if (!curatorId) { 17 return this.unauthorized(res); 18 } 19 20 if (!url) { 21 return this.badRequest(res, 'URL is required'); 22 } 23 24 const result = await this.addUrlToLibraryUseCase.execute({ 25 url, 26 note, 27 collectionIds: collectionIds || [], 28 curatorId, 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}