Skip to content

Commit

Permalink
chore : Swagger 명세 수정 및 Request DTO validator 작성
Browse files Browse the repository at this point in the history
Co-authored-by: 5tarry <hacherry05@naver.com>
  • Loading branch information
msjang4 and 5tarry committed Dec 1, 2023
1 parent d5e96c2 commit 12a6771
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion server/src/exceptions/enum/exception.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const ErrorMessage = {
[ErrorCode.NeverViewVideo]: '시청한 영상만 별점을 등록할 수 있음',
[ErrorCode.VideoNotFound]: '비디오를 찾을 수 없음',
[ErrorCode.UserNotFound]: '유저를 찾을 수 없음',
[ErrorCode.ObjectNotFound]: '오브젝트를 찾을 수 없음',
[ErrorCode.ObjectNotFound]: '파일을 찾을 수 없음',
[ErrorCode.ProfileUploadRequired]: '프로필 이미지를 먼저 업로드 해야합니다.',
[ErrorCode.ThumbnailUploadRequired]: '썸네일을 먼저 업로드 해야합니다.',
[ErrorCode.VideoUploadRequired]: '비디오를 먼저 업로드 해야합니다.',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { IsNotEmpty, IsOptional } from 'class-validator';

export class AdvertisementPresignedUrlRequestDto {
/**
* 특정 광고 이미지의 presigned url만 받고 싶은 경우
* @example 'test.webp'
*/
@IsOptional()
@IsNotEmpty()
name?: string;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { IsNotEmpty } from 'class-validator';

export class ProfilePresignedUrlRequestDto {
/**
* 프로필 이미지 확장자
* @example 'webp'
*/
@IsNotEmpty()
profileExtension: string;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsEnum } from 'class-validator';
import { IsEnum, IsNotEmpty } from 'class-validator';

enum TypeEnum {
thumbnail = 'thumbnail',
Expand All @@ -17,5 +17,6 @@ export class ReissuePresignedUrlRequestDto {
* 이미지 확장자
* @example 'webp'
*/
@IsNotEmpty()
extension: string;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { IsNotEmpty } from 'class-validator';

export class VIdeoPresignedUrlRequestDto {
/**
* 비디오 확장자
* @example 'mp4'
*/
@IsNotEmpty()
videoExtension: string;

/**
* 썸네일 이미지 확장자
* @example 'webp'
*/
@IsNotEmpty()
thumbnailExtension: string;
}
3 changes: 3 additions & 0 deletions server/src/presigned-url/presigned-url.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -32,6 +33,7 @@ export class PresignedUrlController {
'광고 이미지 가져오는 url 발급 성공',
AdvertisementPresignedUrlResponseDto,
)
@ApiFailResponse('url 발급 실패', [ObjectNotFoundException])
getAdvertisementPresignedUrl(
@Query() query: AdvertisementPresignedUrlRequestDto,
) {
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion server/src/user/dto/rated-video-request.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsInt, IsPositive } from 'class-validator';
import { IsInt, IsPositive, IsOptional, IsNotEmpty } from 'class-validator';

export class UserRatedVideoQueryDto {
/**
Expand All @@ -11,5 +11,7 @@ export class UserRatedVideoQueryDto {
/**
* 마지막으로 조회한 비디오의 ratedAt
*/
@IsOptional()
@IsNotEmpty()
lastRatedAt?: string;
}
4 changes: 3 additions & 1 deletion server/src/user/dto/uploaded-video-request.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsInt, IsPositive } from 'class-validator';
import { IsInt, IsNotEmpty, IsOptional, IsPositive } from 'class-validator';

export class UserUploadedVideoQueryDto {
/**
Expand All @@ -11,5 +11,7 @@ export class UserUploadedVideoQueryDto {
/**
* 마지막으로 조회한 비디오 ID
*/
@IsOptional()
@IsNotEmpty()
lastId?: string;
}
7 changes: 3 additions & 4 deletions server/src/video/video.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Query,
} from '@nestjs/common';
import {
ApiBadRequestResponse,
ApiBearerAuth,
ApiOkResponse,
ApiProduces,
Expand All @@ -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';
Expand All @@ -55,7 +55,6 @@ export class VideoController {
constructor(
private videoService: VideoService,
private actionService: ActionService,
private fileExtensionPipe: FileExtensionPipe,
) {}

/**
Expand Down Expand Up @@ -83,8 +82,8 @@ export class VideoController {
@ApiSuccessResponse(201, '비디오 업로드 성공', VideoSummaryResponseDto)
@ApiFailResponse('중복된 비디오 ID', [VideoConflictException])
@ApiFailResponse('잘못된 비디오 ID', [BadRequestFormatException])
@ApiFailResponse('비디오가 업로드 되지 않음', [VideoUploadRequiredException])
@ApiFailResponse('썸네일이 업로드 되지 않음', [
@ApiFailResponse('업로드가 필요함', [
VideoUploadRequiredException,
ThumbnailUploadRequiredException,
])
uploadVideo(
Expand Down

0 comments on commit 12a6771

Please sign in to comment.