Skip to content

Commit 888835a

Browse files
authored
Merge pull request #28 from CodIN-INU/develop
fix: #25 #27 변경사항 적용
2 parents a97099b + 268262a commit 888835a

5 files changed

Lines changed: 46 additions & 19 deletions

File tree

src/main/java/inu/codin/codin/domain/elasticsearch/service/LectureElasticService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public Page<LectureDocument> searchLectureDocument(
7676
b.filter(f -> f.term(t -> t.field("department").value(department.name())));
7777
}
7878

79-
if (like && likeIdList != null && !likeIdList.isEmpty()) {
79+
if (Boolean.TRUE.equals(like) && likeIdList != null && !likeIdList.isEmpty()) {
8080
b.filter(f -> f.ids(i -> i.values(likeIdList)));
8181
}
8282

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
package inu.codin.codin.domain.lecture.converter;
22

33
import inu.codin.codin.domain.lecture.entity.Evaluation;
4+
import inu.codin.codin.domain.lecture.exception.LectureErrorCode;
5+
import inu.codin.codin.domain.lecture.exception.LectureException;
46
import jakarta.persistence.AttributeConverter;
57
import jakarta.persistence.Converter;
8+
import lombok.extern.slf4j.Slf4j;
69

10+
@Slf4j
711
@Converter(autoApply = true)
812
public class EvaluationConverter implements AttributeConverter<Evaluation, String> {
913
@Override
1014
public String convertToDatabaseColumn(Evaluation attribute) {
11-
return attribute.getDescription();
15+
return attribute != null ? attribute.getDescription() : null;
1216
}
1317

1418
@Override
15-
public Evaluation convertToEntityAttribute(String dbData) {
16-
return Evaluation.fromDescription(dbData);
19+
public Evaluation convertToEntityAttribute(String data) {
20+
if (data == null || data.trim().isEmpty()) {
21+
return null;
22+
}
23+
24+
try {
25+
return Evaluation.fromDescription(data.trim());
26+
} catch (IllegalArgumentException e) {
27+
log.warn("Evaluation Converter 부분에서 문제가 발생했습니다.");
28+
throw new LectureException(LectureErrorCode.CONVERT_ERROR);
29+
}
1730
}
1831
}

src/main/java/inu/codin/codin/domain/lecture/entity/Evaluation.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,20 @@ public String getDescription(){
1919

2020
@JsonCreator
2121
public static Evaluation fromDescription(String description) {
22+
if (description == null) {
23+
return null;
24+
}
25+
2226
for (Evaluation evaluation : Evaluation.values()) {
2327
if (evaluation.getDescription().equals(description)) {
2428
return evaluation;
2529
}
2630
}
27-
return null;
31+
32+
try {
33+
return Evaluation.valueOf(description);
34+
} catch (IllegalArgumentException e) {
35+
throw new IllegalArgumentException("Unknown evaluation: " + description);
36+
}
2837
}
2938
}

src/main/java/inu/codin/codin/domain/lecture/entity/Lecture.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package inu.codin.codin.domain.lecture.entity;
22

3+
import inu.codin.codin.domain.lecture.converter.EvaluationConverter;
34
import inu.codin.codin.domain.lecture.converter.StringListConverter;
45
import inu.codin.codin.domain.review.entity.Review;
56
import inu.codin.codin.global.common.entity.Department;
@@ -28,17 +29,15 @@ public class Lecture {
2829

2930
@Enumerated(EnumType.STRING)
3031
private Department department; //학과 (OTHERS : 교양)
31-
32-
@Enumerated(EnumType.STRING)
3332
private Type type; //수업 유형(전공핵심, 전공선택..)
3433
private String lectureType; //수업 방식(강의(이론), 온오프라인혼합형..)
3534

36-
@Enumerated(EnumType.STRING)
35+
@Convert(converter = EvaluationConverter.class)
3736
private Evaluation evaluation; //평가 방식(상대평가, 절대평가, 이수)
3837

3938
// Json 형태로 저장
4039
@Convert(converter = StringListConverter.class)
41-
private List<String> preCourse; //사전 과목 //todo List로 관리 피룡
40+
private List<String> preCourse; //사전 과목
4241
private double starRating; //과목 평점
4342
private int likes; //좋아요 수
4443
private int hits; //조회 수

src/main/java/inu/codin/codin/global/common/exception/GlobalExceptionHandler.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,25 @@ public class GlobalExceptionHandler {
2020

2121
@ExceptionHandler(Exception.class)
2222
protected ResponseEntity<ExceptionResponse> handleException(Exception e) {
23-
StackTraceElement stackTraceElement = e.getStackTrace()[0];
23+
StackTraceElement[] stack = e.getStackTrace();
2424

25-
log.warn("[Exception] 발생 위치: {}.{}({}:{}) | 원인: {} - {}",
26-
stackTraceElement.getClassName(), // 클래스 이름
27-
stackTraceElement.getMethodName(), // 메서드 이름
28-
stackTraceElement.getFileName(), // 파일 이름
29-
stackTraceElement.getLineNumber(), // 라인 번호
30-
e.getClass().getSimpleName(), // 예외 타입
31-
e.getMessage() // 예외 메시지
32-
);
25+
if (stack != null && stack.length > 0) {
26+
StackTraceElement stackTraceElement = stack[0];
27+
28+
log.error("[Exception] 발생 위치: {}.{}({}:{}) | 원인: {} - {}",
29+
stackTraceElement.getClassName(),
30+
stackTraceElement.getMethodName(),
31+
stackTraceElement.getFileName(),
32+
stackTraceElement.getLineNumber(),
33+
e.getClass().getSimpleName(),
34+
e.getMessage(),
35+
e);
36+
} else {
37+
log.error("[Exception] 원인: {} - {}", e.getClass().getSimpleName(), e.getMessage(), e);
38+
}
3339

3440
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
35-
.body(new ExceptionResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()));
41+
.body(new ExceptionResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "서버 내부 오류가 발생했습니다."));
3642
}
3743

3844
@ExceptionHandler(LectureException.class)

0 commit comments

Comments
 (0)