Skip to content

Commit 6778001

Browse files
committed
πŸ“ docs: 파일 응닡 dto 적용 및 λ¬Έμ„œ μˆ˜μ •
1 parent 6c9b3e9 commit 6778001

File tree

4 files changed

+58
-38
lines changed

4 files changed

+58
-38
lines changed

β€Žserver/src/file/api-docs/uploadProfileFile.api-docs.tsβ€Ž

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,41 @@ export function ApiUploadProfileFile() {
4040
data: {
4141
type: 'object',
4242
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-
},
43+
id: {
44+
type: 'number',
45+
example: 1,
46+
description: '파일 ID',
47+
},
48+
originalName: {
49+
type: 'string',
50+
example: 'my-photo.jpg',
51+
description: '원본 파일λͺ…',
52+
},
53+
mimetype: {
54+
type: 'string',
55+
example: 'image/jpeg',
56+
description: '파일 MIME Type',
57+
},
58+
size: {
59+
type: 'number',
60+
example: 1024000,
61+
description: '파일 크기 (bytes)',
62+
},
63+
url: {
64+
type: 'string',
65+
example: '/objects/profile/2024/01/profile-image.jpg',
66+
description: '파일 μ ‘κ·Ό URL',
67+
},
68+
userId: {
69+
type: 'number',
70+
example: 123,
71+
description: 'μ—…λ‘œλ“œν•œ μ‚¬μš©μž ID',
72+
},
73+
createdAt: {
74+
type: 'string',
75+
format: 'date-time',
76+
example: '2024-01-01T12:00:00.000Z',
77+
description: 'μ—…λ‘œλ“œ λ‚ μ§œ',
7178
},
7279
},
7380
},

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { createDynamicStorage } from '../../common/disk/diskStorage';
1818
import { ApiResponse } from '../../common/response/common.response';
1919
import { ApiUploadProfileFile } from '../api-docs/uploadProfileFile.api-docs';
2020
import { ApiDeleteFile } from '../api-docs/deleteFile.api-docs';
21+
import { FileUploadResponseDto } from '../dto/createFile.dto';
2122

2223
@ApiTags('File')
2324
@Controller('file')
@@ -33,14 +34,15 @@ export class FileController {
3334
throw new BadRequestException('파일이 μ„ νƒλ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€.');
3435
}
3536

36-
const resultFile = await this.fileService.create(
37+
const responseDto = await this.fileService.create(
3738
file,
3839
Number.parseInt(req.user.id),
3940
);
4041

41-
return ApiResponse.responseWithData('파일 μ—…λ‘œλ“œμ— μ„±κ³΅ν–ˆμŠ΅λ‹ˆλ‹€.', {
42-
resultFile,
43-
});
42+
return ApiResponse.responseWithData(
43+
'파일 μ—…λ‘œλ“œμ— μ„±κ³΅ν–ˆμŠ΅λ‹ˆλ‹€.',
44+
responseDto,
45+
);
4446
}
4547

4648
// TODO: κΆŒν•œκ²€μ‚¬ μΆ”κ°€
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
import { ApiProperty } from '@nestjs/swagger';
2-
import { IsOptional, IsString, MaxLength } from 'class-validator';
32

43
export class FileUploadResponseDto {
54
@ApiProperty({ description: '파일 ID' })
65
id: number;
76

8-
@ApiProperty({ description: 'μ €μž₯된 파일λͺ…' })
9-
filename: string;
7+
@ApiProperty({ description: '원본 파일λͺ…' })
8+
originalName: string;
109

1110
@ApiProperty({ description: '파일 MIME Type' })
12-
mimeType: string;
11+
mimetype: string;
1312

1413
@ApiProperty({ description: '파일 크기 (bytes)' })
1514
size: number;
1615

16+
@ApiProperty({ description: '파일 μ ‘κ·Ό URL' })
17+
url: string;
18+
19+
@ApiProperty({ description: 'μ—…λ‘œλ“œν•œ μ‚¬μš©μž ID' })
20+
userId: number;
21+
1722
@ApiProperty({ description: 'μ—…λ‘œλ“œ λ‚ μ§œ' })
1823
createdAt: Date;
1924
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import { File } from '../entity/file.entity';
33
import { unlinkSync, existsSync } from 'fs';
44
import { FileRepository } from '../repository/file.repository';
55
import { User } from '../../user/entity/user.entity';
6+
import { FileUploadResponseDto } from '../dto/createFile.dto';
67

78
@Injectable()
89
export class FileService {
910
constructor(private readonly fileRepository: FileRepository) {}
1011

11-
async create(file: any, userId: number) {
12+
async create(file: any, userId: number): Promise<FileUploadResponseDto> {
1213
const { originalName, mimetype, size, path } = file;
1314

1415
const savedFile = await this.fileRepository.save({
@@ -21,8 +22,13 @@ export class FileService {
2122
const accessUrl = this.generateAccessUrl(path);
2223

2324
return {
24-
...savedFile,
25+
id: savedFile.id,
26+
originalName: savedFile.originalName,
27+
mimetype: savedFile.mimetype,
28+
size: savedFile.size,
2529
url: accessUrl,
30+
userId: userId,
31+
createdAt: savedFile.createdAt,
2632
};
2733
}
2834

0 commit comments

Comments
Β (0)