Skip to content

Commit ef1b9c3

Browse files
committed
✨ feat: 파일 추가 API DTO 디렉토리 위치 수정 및 example 추가
1 parent 87ef839 commit ef1b9c3

File tree

2 files changed

+62
-24
lines changed

2 files changed

+62
-24
lines changed

server/src/file/dto/createFile.dto.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { File } from '../../entity/file.entity';
3+
4+
export class FileUploadResponseDto {
5+
@ApiProperty({
6+
example: 1,
7+
description: '파일 ID',
8+
})
9+
id: number;
10+
11+
@ApiProperty({
12+
example: 'example.jpg',
13+
description: '원본 파일명',
14+
})
15+
originalName: string;
16+
17+
@ApiProperty({
18+
example: 'image/jpeg',
19+
description: '파일 MIME Type',
20+
})
21+
mimetype: string;
22+
23+
@ApiProperty({
24+
example: 1024000,
25+
description: '파일 크기 (bytes)',
26+
})
27+
size: number;
28+
29+
@ApiProperty({
30+
example: '/objects/profile/2024/01/example.jpg',
31+
description: '파일 접근 URL',
32+
})
33+
url: string;
34+
35+
@ApiProperty({
36+
example: 1,
37+
description: '업로드한 사용자 ID',
38+
})
39+
userId: number;
40+
41+
@ApiProperty({
42+
example: '2024-01-01T12:00:00.000Z',
43+
description: '업로드 날짜',
44+
})
45+
createdAt: Date;
46+
47+
private constructor(partial: Partial<FileUploadResponseDto>) {
48+
Object.assign(this, partial);
49+
}
50+
51+
static toResponseDto(savedFile: File, accessUrl: string) {
52+
return new FileUploadResponseDto({
53+
id: savedFile.id,
54+
originalName: savedFile.originalName,
55+
mimetype: savedFile.mimetype,
56+
size: savedFile.size,
57+
url: accessUrl,
58+
userId: savedFile.user.id,
59+
createdAt: savedFile.createdAt,
60+
});
61+
}
62+
}

0 commit comments

Comments
 (0)