From 0cfc5e469ffe7bdf7787a27f2fec41119a1ad493 Mon Sep 17 00:00:00 2001 From: BGuga Date: Tue, 15 Aug 2023 18:10:07 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20length=20=EA=B2=80=EC=A6=9D=20=EC=A0=84?= =?UTF-8?q?=20null=20check=20=EA=B0=80=20=EC=84=A0=ED=96=89=EB=90=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/festago/domain/Festival.java | 11 +++++++++-- .../main/java/com/festago/domain/Member.java | 17 ++++++++++++----- .../src/main/java/com/festago/domain/Stage.java | 9 ++++++++- 3 files changed, 29 insertions(+), 8 deletions(-) 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);