diff --git a/src/file/file.controller.ts b/src/file/file.controller.ts index 8a5a11b..8b74867 100644 --- a/src/file/file.controller.ts +++ b/src/file/file.controller.ts @@ -3,6 +3,10 @@ import { JwtAuthGuard } from '@/guard/jwt-auth.guard' import { Body, Controller, + Get, + HttpException, + HttpStatus, + Param, Post, Request, UploadedFile, @@ -17,11 +21,11 @@ import { FileService } from './file.service' import { fileStorage } from './storage' @ApiTags('File') -@UseGuards(JwtAuthGuard) @Controller('file') export class FileController { constructor(private readonly fileService: FileService) {} + @UseGuards(JwtAuthGuard) @Post() @UseInterceptors( FileInterceptor('file', { @@ -47,4 +51,24 @@ export class FileController { ) { return await this.fileService.create(userId, file) } + + @Get('fileName/:fileName') + async findById(@Param('fileName') fileName: string) { + try { + return await this.fileService.findByFileName(fileName) + } catch (e) { + throw new HttpException({ message: e.message }, HttpStatus.BAD_REQUEST) + } + } + + @UseGuards(JwtAuthGuard) + @ApiBearerAuth() + @Get('userId') + async findByUserId(@GetUserIdByToken() userId: string) { + try { + return await this.fileService.findByUserId(userId) + } catch (e) { + throw new HttpException({ message: e.message }, HttpStatus.BAD_REQUEST) + } + } } diff --git a/src/file/file.service.ts b/src/file/file.service.ts index 5cbe011..1e9077e 100644 --- a/src/file/file.service.ts +++ b/src/file/file.service.ts @@ -30,4 +30,8 @@ export class FileService { async findByFileName(fileName: string) { return await this.fileModel.findOne({ fileName }) } + + async findByUserId(userId: string) { + return await this.fileModel.find({ userId }) + } }