-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from zzuda/feature/FileUpload-Swagger
파일 업로드 기능 Swagger 설명 추가
- Loading branch information
Showing
6 changed files
with
101 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { IsNumberString, IsOptional, IsString } from 'class-validator'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class FileBodyDTO { | ||
@IsNumberString() | ||
@ApiProperty({ type: Number, description: '방 ID' }) | ||
roomId!: number; | ||
|
||
@IsString() | ||
@IsOptional() | ||
@ApiProperty({ type: String, description: '파일 이름', required: false }) | ||
fileName?: string; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,74 @@ | ||
import { Controller, Post, UploadedFiles, UseInterceptors, Body } from '@nestjs/common'; | ||
import { FilesInterceptor } from '@nestjs/platform-express'; | ||
import { Express } from 'express'; | ||
/* eslint-disable max-classes-per-file */ | ||
import {Controller, Post, UploadedFiles, UseInterceptors, Body} from '@nestjs/common'; | ||
import { | ||
ApiTags, | ||
ApiOperation, | ||
ApiBody, | ||
PickType, | ||
ApiBadRequestResponse, | ||
ApiInternalServerErrorResponse, | ||
ApiNotFoundResponse | ||
} from '@nestjs/swagger' | ||
import {FilesInterceptor} from '@nestjs/platform-express'; | ||
import {Express} from 'express'; | ||
|
||
import { FileService } from './file.service'; | ||
import { FileBodyDTO } from './dto/upload-file-body.dto'; | ||
import {FileService} from './file.service'; | ||
import {FileBodyDTO} from './dto/file-body.dto'; | ||
|
||
export class FileUploadDTO extends PickType(FileBodyDTO, ['roomId']) {} | ||
|
||
export class FileStorageDTO extends PickType(FileBodyDTO, ['roomId']) {} | ||
|
||
@Controller('file') | ||
@ApiTags("file") | ||
export class FileController { | ||
constructor(private readonly fileService: FileService) {} | ||
constructor(private readonly fileService : FileService) {} | ||
|
||
@Post('upload') | ||
@UseInterceptors( | ||
FilesInterceptor('files', 20, { | ||
dest: './fileStorage/temp' | ||
@Post('upload') | ||
@ApiOperation({ | ||
summary: '파일 업로드 API', | ||
description: '- 파일을 업로드 합니다 \n - 한 파일당 최대 크기는 100MB \n - 한번에 최대 20개 까지 업로드 할 수 있습니다 \n - 해당 ' + | ||
'방 ID에 해당하는 roomStorage(저장 스토리지)가 존재하지 않으면 자동 생성됩니다.' | ||
}) | ||
) | ||
uploadFiles( | ||
@UploadedFiles() files: Express.Multer.File[], | ||
@Body() fileBodyDTO: FileBodyDTO | ||
): string { | ||
const result = this.fileService.moveFile(files, fileBodyDTO); | ||
@ApiBody({type: FileUploadDTO}) | ||
@ApiBadRequestResponse() | ||
@ApiInternalServerErrorResponse() | ||
@UseInterceptors(FilesInterceptor('files', 20, {dest: './fileStorage/temp'})) | ||
uploadFiles( | ||
@UploadedFiles()files : Express.Multer.File[], | ||
@Body()fileBodyDTO : FileBodyDTO | ||
): string { | ||
const result = this | ||
.fileService | ||
.moveFile(files, fileBodyDTO); | ||
|
||
return result; | ||
} | ||
return result; | ||
} | ||
|
||
@Post('delete') | ||
deleteFile(@Body() FileBody: FileBodyDTO): string { | ||
const result = this.fileService.deleteFile(FileBody); | ||
@Post('delete') | ||
@ApiOperation({summary: '파일 삭제', description: '- 해당 roomId에 해당하는 파일을 삭제합니다'}) | ||
@ApiBody({type: FileBodyDTO}) | ||
@ApiInternalServerErrorResponse() | ||
deleteFile(@Body()FileBody : FileBodyDTO): string { | ||
const result = this | ||
.fileService | ||
.deleteFile(FileBody); | ||
|
||
return result; | ||
} | ||
return result; | ||
} | ||
|
||
@Post('deleteStorage') | ||
deleteDir(@Body() roomID: FileBodyDTO): string { | ||
const result = this.fileService.removeRoomStorage(roomID); | ||
@Post('deleteStorage') | ||
@ApiOperation( | ||
{summary: '파일 스토리지 삭제', description: '- 해당 roomId에 해당하는 저장공간을 삭제합니다'} | ||
) | ||
@ApiBody({type: FileStorageDTO}) | ||
@ApiInternalServerErrorResponse() | ||
@ApiNotFoundResponse() | ||
deleteDir(@Body()roomID : FileBodyDTO): string { | ||
const result = this | ||
.fileService | ||
.removeRoomStorage(roomID); | ||
|
||
return result; | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ErrorInfo } from 'src/types'; | ||
|
||
export const AttendError: ErrorInfo = { | ||
WRONG_ATTENDANCE_TYPE: { | ||
code: 'attend-404', | ||
message: '해당 attendance 타입은 존재하지 않습니다.' | ||
}, | ||
ROOM_ALREADY_EXIST: { | ||
code: 'attend-409', | ||
message: '해당 방의 초대 코드가 이미 생성되어 있습니다.' | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters