Skip to content

Commit fc97210

Browse files
committed
πŸ“ docs: 파일 μ—…λ‘œλ“œ API Swagger λ¬Έμ„œ μž‘μ„±
1 parent ebb4b04 commit fc97210

File tree

5 files changed

+175
-0
lines changed

5 files changed

+175
-0
lines changed

β€Žserver/src/app.module.tsβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { MetricsModule } from './common/metrics/metrics.module';
1818
import { APP_INTERCEPTOR } from '@nestjs/core';
1919
import { MetricsInterceptor } from './common/metrics/metrics.interceptor';
2020
import { LikeModule } from './like/module/like.module';
21+
import { FileModule } from './file/module/file.module';
2122

2223
@Module({
2324
imports: [
@@ -50,6 +51,7 @@ import { LikeModule } from './like/module/like.module';
5051
CommentModule,
5152
MetricsModule,
5253
LikeModule,
54+
FileModule,
5355
],
5456
controllers: [],
5557
providers: [

β€Žserver/src/common/swagger/swagger.tsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function setupSwagger(app: INestApplication) {
1616
.addTag('Statistic', '톡계 정보 쑰회 API')
1717
.addTag('User', 'μ‚¬μš©μž 관리와 인증 κ΄€λ ¨ API')
1818
.addTag('OAuth', 'OAuth κ΄€λ ¨ API')
19+
.addTag('File', '파일 μ—…λ‘œλ“œ 및 관리 API')
1920
.setLicense('MIT License', 'https://opensource.org/licenses/MIT')
2021
.build();
2122

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { applyDecorators } from '@nestjs/common';
2+
import {
3+
ApiBadRequestResponse,
4+
ApiNotFoundResponse,
5+
ApiOkResponse,
6+
ApiOperation,
7+
ApiParam,
8+
ApiUnauthorizedResponse,
9+
} from '@nestjs/swagger';
10+
11+
export function ApiDeleteFile() {
12+
return applyDecorators(
13+
ApiOperation({
14+
summary: '파일 μ‚­μ œ API',
15+
description: 'μ—…λ‘œλ“œλœ νŒŒμΌμ„ μ‚­μ œν•©λ‹ˆλ‹€.',
16+
}),
17+
ApiParam({
18+
name: 'id',
19+
description: 'μ‚­μ œν•  파일의 ID',
20+
type: 'string',
21+
example: 'uuid-string',
22+
}),
23+
ApiOkResponse({
24+
description: '파일 μ‚­μ œ 성곡',
25+
schema: {
26+
properties: {
27+
message: {
28+
type: 'string',
29+
example: '파일이 μ„±κ³΅μ μœΌλ‘œ μ‚­μ œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.',
30+
},
31+
},
32+
},
33+
}),
34+
ApiBadRequestResponse({
35+
description: '잘λͺ»λœ μš”μ²­',
36+
schema: {
37+
properties: {
38+
message: {
39+
type: 'string',
40+
example: 'μœ νš¨ν•˜μ§€ μ•Šμ€ 파일 IDμž…λ‹ˆλ‹€.',
41+
},
42+
},
43+
},
44+
}),
45+
ApiNotFoundResponse({
46+
description: 'νŒŒμΌμ„ 찾을 수 μ—†μŒ',
47+
schema: {
48+
properties: {
49+
message: {
50+
type: 'string',
51+
example: 'νŒŒμΌμ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€.',
52+
},
53+
},
54+
},
55+
}),
56+
ApiUnauthorizedResponse({
57+
description: 'μΈμ¦λ˜μ§€ μ•Šμ€ μ‚¬μš©μž',
58+
schema: {
59+
properties: {
60+
message: {
61+
type: 'string',
62+
example: '인증이 ν•„μš”ν•©λ‹ˆλ‹€.',
63+
},
64+
},
65+
},
66+
}),
67+
);
68+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { applyDecorators } from '@nestjs/common';
2+
import {
3+
ApiBadRequestResponse,
4+
ApiBody,
5+
ApiConsumes,
6+
ApiOkResponse,
7+
ApiOperation,
8+
ApiUnauthorizedResponse,
9+
} from '@nestjs/swagger';
10+
11+
export function ApiUploadProfileFile() {
12+
return applyDecorators(
13+
ApiOperation({
14+
summary: 'ν”„λ‘œν•„ 이미지 μ—…λ‘œλ“œ API',
15+
description: 'μ‚¬μš©μžμ˜ ν”„λ‘œν•„ 이미지λ₯Ό μ—…λ‘œλ“œν•©λ‹ˆλ‹€.',
16+
}),
17+
ApiConsumes('multipart/form-data'),
18+
ApiBody({
19+
description: 'μ—…λ‘œλ“œν•  파일',
20+
schema: {
21+
type: 'object',
22+
properties: {
23+
file: {
24+
type: 'string',
25+
format: 'binary',
26+
description: 'μ—…λ‘œλ“œν•  이미지 파일 (JPG, PNG, GIF λ“±)',
27+
},
28+
},
29+
required: ['file'],
30+
},
31+
}),
32+
ApiOkResponse({
33+
description: '파일 μ—…λ‘œλ“œ 성곡',
34+
schema: {
35+
properties: {
36+
message: {
37+
type: 'string',
38+
example: '파일 μ—…λ‘œλ“œμ— μ„±κ³΅ν–ˆμŠ΅λ‹ˆλ‹€.',
39+
},
40+
data: {
41+
type: 'object',
42+
properties: {
43+
resultFile: {
44+
type: 'object',
45+
properties: {
46+
id: {
47+
type: 'string',
48+
example: 'uuid-string',
49+
},
50+
filename: {
51+
type: 'string',
52+
example: 'profile-image.jpg',
53+
},
54+
originalName: {
55+
type: 'string',
56+
example: 'my-photo.jpg',
57+
},
58+
mimeType: {
59+
type: 'string',
60+
example: 'image/jpeg',
61+
},
62+
size: {
63+
type: 'number',
64+
example: 1024000,
65+
},
66+
path: {
67+
type: 'string',
68+
example: '/uploads/profile/uuid-string.jpg',
69+
},
70+
},
71+
},
72+
},
73+
},
74+
},
75+
},
76+
}),
77+
ApiBadRequestResponse({
78+
description: '잘λͺ»λœ μš”μ²­',
79+
schema: {
80+
properties: {
81+
message: {
82+
type: 'string',
83+
example: '파일이 μ„ νƒλ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€.',
84+
},
85+
},
86+
},
87+
}),
88+
ApiUnauthorizedResponse({
89+
description: 'μΈμ¦λ˜μ§€ μ•Šμ€ μ‚¬μš©μž',
90+
schema: {
91+
properties: {
92+
message: {
93+
type: 'string',
94+
example: '인증이 ν•„μš”ν•©λ‹ˆλ‹€.',
95+
},
96+
},
97+
},
98+
}),
99+
);
100+
}

β€Žserver/src/file/controller/file.controller.tsβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ import { ApiTags } from '@nestjs/swagger';
1616
import { JwtGuard } from '../../common/guard/jwt.guard';
1717
import { createDynamicStorage } from '../../common/disk/diskStorage';
1818
import { ApiResponse } from '../../common/response/common.response';
19+
import { ApiUploadProfileFile } from '../api-docs/uploadProfileFile.api-docs';
20+
import { ApiDeleteFile } from '../api-docs/deleteFile.api-docs';
1921
@ApiTags('File')
2022
@Controller('file')
2123
@UseGuards(JwtGuard)
2224
export class FileController {
2325
constructor(private readonly fileService: FileService) {}
2426

2527
@Post('upload/profile')
28+
@ApiUploadProfileFile()
2629
@UseInterceptors(FileInterceptor('file', createDynamicStorage()))
2730
async upload(@UploadedFile() file: any, @Req() req) {
2831
if (!file) {
@@ -41,6 +44,7 @@ export class FileController {
4144

4245
// TODO: κΆŒν•œκ²€μ‚¬ μΆ”κ°€
4346
@Delete(':id')
47+
@ApiDeleteFile()
4448
async deleteFile(@Param('id') id: string, @Req() req) {
4549
await this.fileService.deleteFile(id);
4650
return { message: '파일이 μ„±κ³΅μ μœΌλ‘œ μ‚­μ œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.' };

0 commit comments

Comments
Β (0)