Skip to content

Commit

Permalink
Merge pull request #85 from study-hub-inu/fix/SH-313-major-post
Browse files Browse the repository at this point in the history
[Fix] : 학과별 검색 조회 수정
  • Loading branch information
wellbeing-dough authored Feb 11, 2024
2 parents d0b3028 + 947d3fb commit 9c4f1bd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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("전공없음"),
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 9c4f1bd

Please sign in to comment.