From 947d3fb93f67049202afbca498daa684a159ebe6 Mon Sep 17 00:00:00 2001 From: wellbeing-dough Date: Sun, 11 Feb 2024 16:36:07 +0900 Subject: [PATCH] =?UTF-8?q?[Fix]=20:=20=ED=95=99=EA=B3=BC=EB=B3=84=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=20=EC=A1=B0=ED=9A=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../studyhubserver/exception/StatusType.java | 3 ++- .../user/MajorTypeNotFoundException.java | 24 +++++++++++++++++++ .../repository/StudyPostRepositoryImpl.java | 2 +- .../studyhubserver/user/enums/MajorType.java | 10 ++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 src/main/java/kr/co/studyhubinu/studyhubserver/exception/user/MajorTypeNotFoundException.java diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/exception/StatusType.java b/src/main/java/kr/co/studyhubinu/studyhubserver/exception/StatusType.java index dba5a2e6..c0b3101c 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/exception/StatusType.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/exception/StatusType.java @@ -18,7 +18,8 @@ public enum StatusType { ACCESS_RIGHT_FAILED(412, "ACCESS_RIGHT_FAILED"), DATA_CONFLICT(409, "DATA_CONFLICT"), NOTIFICATION_NOT_FOUND(404, "NOTIFICATION_NOT_FOUND"), - SORT_TYPE_NOT_FOUND(404, "SORT_TYPE_NOT_FOUND"); + SORT_TYPE_NOT_FOUND(404, "SORT_TYPE_NOT_FOUND"), + MAJOR_TYPE_NOT_FOUND(404, "MAJOR_TYPE_NOT_FOUND"); private final int statusCode; private final String code; diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/exception/user/MajorTypeNotFoundException.java b/src/main/java/kr/co/studyhubinu/studyhubserver/exception/user/MajorTypeNotFoundException.java new file mode 100644 index 00000000..8e185f8f --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/exception/user/MajorTypeNotFoundException.java @@ -0,0 +1,24 @@ +package kr.co.studyhubinu.studyhubserver.exception.user; + +import kr.co.studyhubinu.studyhubserver.exception.StatusType; +import kr.co.studyhubinu.studyhubserver.exception.common.CustomException; + +public class MajorTypeNotFoundException extends CustomException { + private final StatusType status; + private static final String message = "전공 타입을 찾을 수 없습니다"; + + public MajorTypeNotFoundException() { + super(message); + this.status = StatusType.MAJOR_TYPE_NOT_FOUND; + } + + @Override + public StatusType getStatus() { + return status; + } + + @Override + public String getMessage() { + return message; + } +} diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepositoryImpl.java b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepositoryImpl.java index 4c8e42ea..dd4d2219 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepositoryImpl.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepositoryImpl.java @@ -187,7 +187,7 @@ private BooleanExpression textEq(String inquiryText) { private Predicate majorEq(String inquiryText, boolean titleAndMajor) { if (inquiryText != null && titleAndMajor) { - return studyPostEntity.major.eq(MajorType.of(inquiryText)); + return studyPostEntity.major.eq(MajorType.findMajorType(inquiryText)); } return null; } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/user/enums/MajorType.java b/src/main/java/kr/co/studyhubinu/studyhubserver/user/enums/MajorType.java index 502da1d9..694b7658 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/user/enums/MajorType.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/user/enums/MajorType.java @@ -1,6 +1,9 @@ package kr.co.studyhubinu.studyhubserver.user.enums; import kr.co.studyhubinu.studyhubserver.common.enums.EnumModel; +import kr.co.studyhubinu.studyhubserver.exception.user.MajorTypeNotFoundException; + +import java.util.Arrays; public enum MajorType implements EnumModel { NONE("전공없음"), @@ -100,4 +103,11 @@ public static MajorType of(String major) { } return NONE; } + + public static MajorType findMajorType(final String text) { + return Arrays.stream(MajorType.values()) + .filter(majorType -> majorType.value.equals(text)) + .findFirst() + .orElseThrow(MajorTypeNotFoundException::new); + } } \ No newline at end of file