diff --git a/backend/src/main/java/com/festago/domain/Festival.java b/backend/src/main/java/com/festago/domain/Festival.java index c2d0bfe0b..cbfb8a102 100644 --- a/backend/src/main/java/com/festago/domain/Festival.java +++ b/backend/src/main/java/com/festago/domain/Festival.java @@ -71,12 +71,19 @@ private void checkNotNull(String name, LocalDate startDate, LocalDate endDate, S } private void checkLength(String name, String thumbnail) { - if (name.length() > 50 || - thumbnail.length() > 255) { + if (overLength(name, 50) || + overLength(thumbnail, 255)) { throw new IllegalArgumentException("Festival 의 필드로 허용된 길이를 넘은 column 을 넣을 수 없습니다."); } } + private boolean overLength(String target, int maxLength) { + if (Objects.isNull(target)) { + return false; + } + return target.length() > maxLength; + } + private void validateDate(LocalDate startDate, LocalDate endDate) { if (startDate.isAfter(endDate)) { throw new BadRequestException(ErrorCode.INVALID_FESTIVAL_DURATION); diff --git a/backend/src/main/java/com/festago/domain/Member.java b/backend/src/main/java/com/festago/domain/Member.java index 4646f79bb..3cfe89ce4 100644 --- a/backend/src/main/java/com/festago/domain/Member.java +++ b/backend/src/main/java/com/festago/domain/Member.java @@ -52,7 +52,7 @@ public Member(String socialId, SocialType socialType, String nickname, String pr } public Member(Long id, String socialId, SocialType socialType, String nickname, String profileImage) { - validate(socialId, socialType, nickname); + validate(socialId, socialType, nickname, profileImage); this.id = id; this.socialId = socialId; this.socialType = socialType; @@ -60,7 +60,7 @@ public Member(Long id, String socialId, SocialType socialType, String nickname, this.profileImage = (profileImage != null) ? profileImage : DEFAULT_IMAGE_URL; } - private void validate(String socialId, SocialType socialType, String nickname) { + private void validate(String socialId, SocialType socialType, String nickname, String profileImage) { checkNotNull(socialId, socialType, nickname); checkLength(socialId, nickname, profileImage); } @@ -74,13 +74,20 @@ private void checkNotNull(String socialId, SocialType socialType, String nicknam } private void checkLength(String socialId, String nickname, String profileImage) { - if (socialId.length() > 255 || - nickname.length() > 30 || - profileImage.length() > 255) { + if (overLength(socialId, 255) || + overLength(nickname, 30) || + overLength(profileImage, 255)) { throw new IllegalArgumentException("Member 의 필드로 허용된 길이를 넘은 column 을 넣을 수 없습니다."); } } + private boolean overLength(String target, int maxLength) { + if (Objects.isNull(target)) { + return false; + } + return target.length() > maxLength; + } + public Long getId() { return id; } diff --git a/backend/src/main/java/com/festago/domain/Stage.java b/backend/src/main/java/com/festago/domain/Stage.java index 72061d1b0..e1b7e10e0 100644 --- a/backend/src/main/java/com/festago/domain/Stage.java +++ b/backend/src/main/java/com/festago/domain/Stage.java @@ -75,11 +75,18 @@ private void checkNotNull(LocalDateTime startTime, LocalDateTime ticketOpenTime, } private void checkLength(String lineUp) { - if (lineUp.length() > 255) { + if (overLength(lineUp, 255)) { throw new IllegalArgumentException("Stage 의 필드로 허용된 범위를 넘은 column 을 넣을 수 없습니다."); } } + private boolean overLength(String target, int maxLength) { + if (Objects.isNull(target)) { + return false; + } + return target.length() > maxLength; + } + private void validateTime(LocalDateTime startTime, LocalDateTime ticketOpenTime, Festival festival) { if (festival.isNotInDuration(startTime)) { throw new BadRequestException(ErrorCode.INVALID_STAGE_START_TIME);