From 12a6771ed4ad90b79e05d65e15331aabb8d15abb Mon Sep 17 00:00:00 2001 From: msjang4 Date: Fri, 1 Dec 2023 22:55:27 +0900 Subject: [PATCH] =?UTF-8?q?chore=20:=20Swagger=20=EB=AA=85=EC=84=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EB=B0=8F=20Request=20DTO=20validator=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 5tarry --- server/src/exceptions/enum/exception.enum.ts | 2 +- .../dto/advertisement-presigned-url-request.dto.ts | 4 ++++ .../presigned-url/dto/profile-presigned-url-request.dto.ts | 3 +++ .../presigned-url/dto/reissue-presigned-url-request.dto.ts | 3 ++- .../presigned-url/dto/video-presigned-url-request.dto.ts | 4 ++++ server/src/presigned-url/presigned-url.controller.ts | 3 +++ server/src/user/dto/rated-video-request.dto.ts | 4 +++- server/src/user/dto/uploaded-video-request.dto.ts | 4 +++- server/src/video/video.controller.ts | 7 +++---- 9 files changed, 26 insertions(+), 8 deletions(-) diff --git a/server/src/exceptions/enum/exception.enum.ts b/server/src/exceptions/enum/exception.enum.ts index a302457..e948621 100644 --- a/server/src/exceptions/enum/exception.enum.ts +++ b/server/src/exceptions/enum/exception.enum.ts @@ -36,7 +36,7 @@ const ErrorMessage = { [ErrorCode.NeverViewVideo]: '시청한 영상만 별점을 등록할 수 있음', [ErrorCode.VideoNotFound]: '비디오를 찾을 수 없음', [ErrorCode.UserNotFound]: '유저를 찾을 수 없음', - [ErrorCode.ObjectNotFound]: '오브젝트를 찾을 수 없음', + [ErrorCode.ObjectNotFound]: '파일을 찾을 수 없음', [ErrorCode.ProfileUploadRequired]: '프로필 이미지를 먼저 업로드 해야합니다.', [ErrorCode.ThumbnailUploadRequired]: '썸네일을 먼저 업로드 해야합니다.', [ErrorCode.VideoUploadRequired]: '비디오를 먼저 업로드 해야합니다.', diff --git a/server/src/presigned-url/dto/advertisement-presigned-url-request.dto.ts b/server/src/presigned-url/dto/advertisement-presigned-url-request.dto.ts index d817b83..741ab5f 100644 --- a/server/src/presigned-url/dto/advertisement-presigned-url-request.dto.ts +++ b/server/src/presigned-url/dto/advertisement-presigned-url-request.dto.ts @@ -1,7 +1,11 @@ +import { IsNotEmpty, IsOptional } from 'class-validator'; + export class AdvertisementPresignedUrlRequestDto { /** * 특정 광고 이미지의 presigned url만 받고 싶은 경우 * @example 'test.webp' */ + @IsOptional() + @IsNotEmpty() name?: string; } diff --git a/server/src/presigned-url/dto/profile-presigned-url-request.dto.ts b/server/src/presigned-url/dto/profile-presigned-url-request.dto.ts index 0506dd5..cc059a2 100644 --- a/server/src/presigned-url/dto/profile-presigned-url-request.dto.ts +++ b/server/src/presigned-url/dto/profile-presigned-url-request.dto.ts @@ -1,7 +1,10 @@ +import { IsNotEmpty } from 'class-validator'; + export class ProfilePresignedUrlRequestDto { /** * 프로필 이미지 확장자 * @example 'webp' */ + @IsNotEmpty() profileExtension: string; } diff --git a/server/src/presigned-url/dto/reissue-presigned-url-request.dto.ts b/server/src/presigned-url/dto/reissue-presigned-url-request.dto.ts index 341d81a..f96e42c 100644 --- a/server/src/presigned-url/dto/reissue-presigned-url-request.dto.ts +++ b/server/src/presigned-url/dto/reissue-presigned-url-request.dto.ts @@ -1,4 +1,4 @@ -import { IsEnum } from 'class-validator'; +import { IsEnum, IsNotEmpty } from 'class-validator'; enum TypeEnum { thumbnail = 'thumbnail', @@ -17,5 +17,6 @@ export class ReissuePresignedUrlRequestDto { * 이미지 확장자 * @example 'webp' */ + @IsNotEmpty() extension: string; } diff --git a/server/src/presigned-url/dto/video-presigned-url-request.dto.ts b/server/src/presigned-url/dto/video-presigned-url-request.dto.ts index 4e93c1a..a4fa2f2 100644 --- a/server/src/presigned-url/dto/video-presigned-url-request.dto.ts +++ b/server/src/presigned-url/dto/video-presigned-url-request.dto.ts @@ -1,13 +1,17 @@ +import { IsNotEmpty } from 'class-validator'; + export class VIdeoPresignedUrlRequestDto { /** * 비디오 확장자 * @example 'mp4' */ + @IsNotEmpty() videoExtension: string; /** * 썸네일 이미지 확장자 * @example 'webp' */ + @IsNotEmpty() thumbnailExtension: string; } diff --git a/server/src/presigned-url/presigned-url.controller.ts b/server/src/presigned-url/presigned-url.controller.ts index dc55cf6..8c8bbfb 100644 --- a/server/src/presigned-url/presigned-url.controller.ts +++ b/server/src/presigned-url/presigned-url.controller.ts @@ -6,6 +6,7 @@ import { InvalidTokenException } from 'src/exceptions/invalid-token.exception'; import { TokenExpiredException } from 'src/exceptions/token-expired.exception'; import { ApiSuccessResponse } from 'src/decorators/api-succes-response'; import { RequestUser, User } from 'src/decorators/request-user'; +import { ObjectNotFoundException } from 'src/exceptions/object-not-found.exception'; import { PresignedUrlService } from './presigned-url.service'; import { AdvertisementPresignedUrlRequestDto } from './dto/advertisement-presigned-url-request.dto'; import { ProfilePresignedUrlRequestDto } from './dto/profile-presigned-url-request.dto'; @@ -32,6 +33,7 @@ export class PresignedUrlController { '광고 이미지 가져오는 url 발급 성공', AdvertisementPresignedUrlResponseDto, ) + @ApiFailResponse('url 발급 실패', [ObjectNotFoundException]) getAdvertisementPresignedUrl( @Query() query: AdvertisementPresignedUrlRequestDto, ) { @@ -79,6 +81,7 @@ export class PresignedUrlController { description: '썸네일 재발급 시 비디오ID, 프로필 재발급 시 유저 UUID', }) @ApiSuccessResponse(200, 'presigned url 재발급 성공', PresignedUrlResponseDto) + @ApiFailResponse('url 발급 실패', [ObjectNotFoundException]) getImagePresignedUrl( @Param('id') id: string, @Query() query: ReissuePresignedUrlRequestDto, diff --git a/server/src/user/dto/rated-video-request.dto.ts b/server/src/user/dto/rated-video-request.dto.ts index d061e79..08aca16 100644 --- a/server/src/user/dto/rated-video-request.dto.ts +++ b/server/src/user/dto/rated-video-request.dto.ts @@ -1,4 +1,4 @@ -import { IsInt, IsPositive } from 'class-validator'; +import { IsInt, IsPositive, IsOptional, IsNotEmpty } from 'class-validator'; export class UserRatedVideoQueryDto { /** @@ -11,5 +11,7 @@ export class UserRatedVideoQueryDto { /** * 마지막으로 조회한 비디오의 ratedAt */ + @IsOptional() + @IsNotEmpty() lastRatedAt?: string; } diff --git a/server/src/user/dto/uploaded-video-request.dto.ts b/server/src/user/dto/uploaded-video-request.dto.ts index 077457c..3efc5de 100644 --- a/server/src/user/dto/uploaded-video-request.dto.ts +++ b/server/src/user/dto/uploaded-video-request.dto.ts @@ -1,4 +1,4 @@ -import { IsInt, IsPositive } from 'class-validator'; +import { IsInt, IsNotEmpty, IsOptional, IsPositive } from 'class-validator'; export class UserUploadedVideoQueryDto { /** @@ -11,5 +11,7 @@ export class UserUploadedVideoQueryDto { /** * 마지막으로 조회한 비디오 ID */ + @IsOptional() + @IsNotEmpty() lastId?: string; } diff --git a/server/src/video/video.controller.ts b/server/src/video/video.controller.ts index 0ce8442..e67b7ef 100644 --- a/server/src/video/video.controller.ts +++ b/server/src/video/video.controller.ts @@ -12,6 +12,7 @@ import { Query, } from '@nestjs/common'; import { + ApiBadRequestResponse, ApiBearerAuth, ApiOkResponse, ApiProduces, @@ -37,7 +38,6 @@ import { BadRequestFormatException } from 'src/exceptions/bad-request-format.exc import { VideoService } from './video.service'; import { VideoDto } from './dto/video.dto'; import { VideoRatingDTO } from './dto/video-rating.dto'; -import { FileExtensionPipe } from './video.pipe'; import { RandomVideoQueryDto } from './dto/random-video-query.dto'; import { VideoSummaryResponseDto } from './dto/video-summary-response.dto'; import { VideoInfoDto } from './dto/video-info.dto'; @@ -55,7 +55,6 @@ export class VideoController { constructor( private videoService: VideoService, private actionService: ActionService, - private fileExtensionPipe: FileExtensionPipe, ) {} /** @@ -83,8 +82,8 @@ export class VideoController { @ApiSuccessResponse(201, '비디오 업로드 성공', VideoSummaryResponseDto) @ApiFailResponse('중복된 비디오 ID', [VideoConflictException]) @ApiFailResponse('잘못된 비디오 ID', [BadRequestFormatException]) - @ApiFailResponse('비디오가 업로드 되지 않음', [VideoUploadRequiredException]) - @ApiFailResponse('썸네일이 업로드 되지 않음', [ + @ApiFailResponse('업로드가 필요함', [ + VideoUploadRequiredException, ThumbnailUploadRequiredException, ]) uploadVideo(