diff --git a/src/main/java/icurriculum/domain/curriculum/data/Core.java b/src/main/java/icurriculum/domain/curriculum/data/Core.java index 3e48e9e..0ff9091 100644 --- a/src/main/java/icurriculum/domain/curriculum/data/Core.java +++ b/src/main/java/icurriculum/domain/curriculum/data/Core.java @@ -103,6 +103,12 @@ public void validate() { if (isAreaFixed == null || requiredCredit == null) { throw new GeneralException(ErrorStatus.CURRICULUM_MISSING_VALUE, this); } + if (!isAreaFixed && !requiredAreaSet.isEmpty()) { + throw new GeneralException(ErrorStatus.CORE_INVALID_DATA, this); + } + if (isAreaFixed && requiredAreaSet.isEmpty()) { + throw new GeneralException(ErrorStatus.CORE_INVALID_DATA, this); + } } private void validateCategory(Category category) { diff --git a/src/main/java/icurriculum/domain/graduation/service/module/processor/core/strategy/CommonCoreStrategy.java b/src/main/java/icurriculum/domain/graduation/service/module/processor/core/strategy/CommonCoreStrategy.java index 002ae5d..dd03ef4 100644 --- a/src/main/java/icurriculum/domain/graduation/service/module/processor/core/strategy/CommonCoreStrategy.java +++ b/src/main/java/icurriculum/domain/graduation/service/module/processor/core/strategy/CommonCoreStrategy.java @@ -63,7 +63,8 @@ private Set handleAreaAlternative( while (iterator.hasNext()) { Take take = iterator.next(); - for (Category area : core.getRequiredAreaSet()) { + Set requiredAreaSet = getRequiredAreaSetWhenHandleAreaAlt(core); + for (Category area : requiredAreaSet) { Set areaAlternativeCodeSet = core.getAreaAlternativeCodeSet(area); if (GraduationUtils.isApproved(take, areaAlternativeCodeSet)) { @@ -85,6 +86,13 @@ private Set handleAreaAlternative( return areaAltCourseSet; } + private Set getRequiredAreaSetWhenHandleAreaAlt(Core core) { + if (!core.getIsAreaFixed()) { + return GraduationUtils.CORE_CATEGORYSET; + } + return core.getRequiredAreaSet(); + } + /* * [core logic] * - 영역 대체를 통해서 이미 계산된 과목은 건너뛴다. diff --git a/src/main/java/icurriculum/global/response/exception/GeneralException.java b/src/main/java/icurriculum/global/response/exception/GeneralException.java index 023f5b6..d0719a0 100644 --- a/src/main/java/icurriculum/global/response/exception/GeneralException.java +++ b/src/main/java/icurriculum/global/response/exception/GeneralException.java @@ -21,4 +21,15 @@ public GeneralException(ErrorStatus errorStatus, Object data) { this.data = data; } -} \ No newline at end of file + public GeneralException(ErrorStatus errorStatus, Throwable cause) { + super(errorStatus.getMessage(), cause); + this.errorStatus = errorStatus; + this.data = null; + } + + public GeneralException(ErrorStatus errorStatus, Object data, Throwable cause) { + super(errorStatus.getMessage(), cause); + this.errorStatus = errorStatus; + this.data = data; + } +} diff --git a/src/main/java/icurriculum/global/response/exception/handler/GlobalExceptionHandler.java b/src/main/java/icurriculum/global/response/exception/handler/GlobalExceptionHandler.java index ea7e4cd..1f3f5b9 100644 --- a/src/main/java/icurriculum/global/response/exception/handler/GlobalExceptionHandler.java +++ b/src/main/java/icurriculum/global/response/exception/handler/GlobalExceptionHandler.java @@ -11,15 +11,14 @@ @RestControllerAdvice public class GlobalExceptionHandler { - /* - * 비즈니스적으로 에러가 발생했을 때 사용됩니다. - */ @ExceptionHandler(GeneralException.class) public ResponseEntity> handleGeneralException(GeneralException ex) { log.error("Error Code: {}, Message: {}, Data: {}", ex.getErrorStatus().getCode(), ex.getErrorStatus().getMessage(), - ex.getData() != null ? ex.getData() : "No additional data"); + ex.getData() != null ? ex.getData() : "No additional data", + ex + ); return ResponseEntity .status(ex.getErrorStatus().getHttpStatus()) diff --git a/src/main/java/icurriculum/global/response/status/ErrorStatus.java b/src/main/java/icurriculum/global/response/status/ErrorStatus.java index 01023c5..f9a09a8 100644 --- a/src/main/java/icurriculum/global/response/status/ErrorStatus.java +++ b/src/main/java/icurriculum/global/response/status/ErrorStatus.java @@ -37,10 +37,12 @@ public enum ErrorStatus { CURRICULUM_NOT_VALID_CATEGORY(HttpStatus.BAD_REQUEST, "CURRICULUM402", "CurriculumCode 에는 전공필수, 전공선택, 교양필수 조회가능합니다."), CORE_NOT_VALID_CATEGORY(HttpStatus.BAD_REQUEST, "CURRICULUM403", - "Core 에는 핵심교양만 조회가능합니다."), - CURRICULUM_MISSING_VALUE(HttpStatus.BAD_REQUEST, "CURRICULUM404", + "Core는 핵심교양만 조회가능합니다."), + CORE_INVALID_DATA(HttpStatus.BAD_REQUEST, "CURRICULUM404", + "Core의 데이터형식이 올바르지 않습니다."), + CURRICULUM_MISSING_VALUE(HttpStatus.BAD_REQUEST, "CURRICULUM405", "Curriculum 내부의 필수값이 빠졌습니다."), - CURRICULUM_DECIDER_MISSING_VALUE(HttpStatus.BAD_REQUEST, "CURRICULUM405", + CURRICULUM_DECIDER_MISSING_VALUE(HttpStatus.BAD_REQUEST, "CURRICULUM406", "CurriculumDecider 내부의 필수값이 빠졌습니다."), /*