Skip to content

Commit

Permalink
[#495] feat: valid 설정 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jyajoo committed Dec 9, 2024
1 parent 7adc953 commit 71255c1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public enum ErrorCode {
SELF_REPORT_NOT_ALLOWED(BAD_REQUEST, "본인을 신고하는 요청은 유효하지 않습니다."),
ALREADY_REPORTED(BAD_REQUEST, "이미 신고되었습니다."),
NO_NOTIFICATION_CONSENT(BAD_REQUEST, "알림 동의를 하지 않은 유저입니다."),
INVALID_FILE_SIZE(BAD_REQUEST, "파일 크기가 유효하지 않습니다."),
INVALID_FILE_EXTENSION_TYPE(BAD_REQUEST, "해당 카테고리에서 지원하지 않는 파일 형식입니다."),
NO_FILE_EXTENSION(BAD_REQUEST, "파일 확장자가 없습니다."),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.jeju.nanaland.domain.common.annotation.EnumValid;
import com.jeju.nanaland.global.file.data.FileCategory;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
Expand All @@ -23,10 +25,12 @@ public static class InitCommandDto {

@NotNull
@Schema(description = "파일 크기")
@Max(30 * 1024 * 1024)
private Long fileSize;

@NotNull
@Schema(description = "파일 파트 개수")
@Min(1)
private int partCount;

@EnumValid(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static com.jeju.nanaland.global.exception.ErrorCode.FILE_S3_NOT_FOUNE;
import static com.jeju.nanaland.global.exception.ErrorCode.FILE_UPLOAD_FAIL;
import static com.jeju.nanaland.global.exception.ErrorCode.INVALID_FILE_EXTENSION_TYPE;
import static com.jeju.nanaland.global.exception.ErrorCode.INVALID_FILE_SIZE;
import static com.jeju.nanaland.global.exception.ErrorCode.NO_FILE_EXTENSION;

import com.amazonaws.HttpMethod;
Expand All @@ -29,7 +28,6 @@
import com.jeju.nanaland.global.image_upload.dto.S3VideoDto;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.net.URL;
import java.time.LocalDate;
import java.time.LocalDateTime;
Expand All @@ -51,7 +49,6 @@ public class FileUploadService {

private static final int MAX_IMAGE_COUNT = 5;
private static final int PRESIGNEDURL_EXPIRATION = 30;
private static final long MAX_FILE_SIZE = 30 * 1024 * 1024L;
private final AmazonS3 amazonS3;
private final AmazonS3Client amazonS3Client;
@Value("${cloud.aws.cloudfront.domain}")
Expand All @@ -68,9 +65,6 @@ public class FileUploadService {
private String claimReportDirectory;

public FileResponse.InitResultDto uploadInit(FileRequest.InitCommandDto initCommandDto) {
// 파일 크기 유효성 검사
validateFileSize(initCommandDto.getFileSize());

// 파일 형식 유효성 검사
String contentType = validateFileExtension(initCommandDto.getOriginalFileName(),
FileCategory.valueOf(initCommandDto.getFileCategory()));
Expand Down Expand Up @@ -121,12 +115,6 @@ public FileResponse.InitResultDto uploadInit(FileRequest.InitCommandDto initComm
}
}

private void validateFileSize(@NotNull Long fileSize) {
if (fileSize > MAX_FILE_SIZE) {
throw new BadRequestException(INVALID_FILE_SIZE.getMessage());
}
}

/**
* 파일 확장자 유효성 확인
*
Expand Down

0 comments on commit 71255c1

Please sign in to comment.