Skip to content

Commit

Permalink
feat: length 검증 전 null check 가 선행되도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
BGuga committed Aug 15, 2023
1 parent a7e25bf commit 0cfc5e4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
11 changes: 9 additions & 2 deletions backend/src/main/java/com/festago/domain/Festival.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 12 additions & 5 deletions backend/src/main/java/com/festago/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ 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;
this.nickname = 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);
}
Expand All @@ -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;
}
Expand Down
9 changes: 8 additions & 1 deletion backend/src/main/java/com/festago/domain/Stage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0cfc5e4

Please sign in to comment.