|
| 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 | + 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: '업로드 날짜', |
| 78 | + }, |
| 79 | + }, |
| 80 | + }, |
| 81 | + }, |
| 82 | + }, |
| 83 | + }), |
| 84 | + ApiBadRequestResponse({ |
| 85 | + description: '잘못된 요청', |
| 86 | + schema: { |
| 87 | + properties: { |
| 88 | + message: { |
| 89 | + type: 'string', |
| 90 | + example: '파일이 선택되지 않았습니다.', |
| 91 | + }, |
| 92 | + }, |
| 93 | + }, |
| 94 | + }), |
| 95 | + ApiUnauthorizedResponse({ |
| 96 | + description: '인증되지 않은 사용자', |
| 97 | + schema: { |
| 98 | + properties: { |
| 99 | + message: { |
| 100 | + type: 'string', |
| 101 | + example: '인증이 필요합니다.', |
| 102 | + }, |
| 103 | + }, |
| 104 | + }, |
| 105 | + }), |
| 106 | + ); |
| 107 | +} |
0 commit comments