diff --git a/src/main/java/com/api/TaveShot/domain/compiler/controller/CompilerController.java b/src/main/java/com/api/TaveShot/domain/compiler/controller/CompilerController.java index a9e52ac..255f007 100644 --- a/src/main/java/com/api/TaveShot/domain/compiler/controller/CompilerController.java +++ b/src/main/java/com/api/TaveShot/domain/compiler/controller/CompilerController.java @@ -28,10 +28,9 @@ public class CompilerController { schema = @Schema(implementation = ProblemDto.class))) }) @GetMapping("/problems/{id}") - public ResponseEntity> getProblem(@PathVariable String id) { - return problemService.getProblemById(id) - .map(problemDto -> ResponseEntity.ok(new SuccessResponse<>(problemDto))) - .orElseGet(() -> ResponseEntity.notFound().build()); + public SuccessResponse getProblem(@PathVariable String id) { + ProblemDto problemDto = problemService.getProblemById(id); + return new SuccessResponse<>(problemDto); } /*@Operation(summary = "코드 컴파일링 및 채점", description = "해당 문제 풀이에 대한 채점 결과를 보여줍니다.") diff --git a/src/main/java/com/api/TaveShot/domain/compiler/service/ProblemService.java b/src/main/java/com/api/TaveShot/domain/compiler/service/ProblemService.java index a57430a..43b1900 100644 --- a/src/main/java/com/api/TaveShot/domain/compiler/service/ProblemService.java +++ b/src/main/java/com/api/TaveShot/domain/compiler/service/ProblemService.java @@ -19,9 +19,10 @@ public class ProblemService { private final ProblemRepository problemRepository; - public Optional getProblemById(String id) { - return problemRepository.findById(id) - .map(ProblemConverter::convertToDto) + public ProblemDto getProblemById(String id) { + BojProblem bojProblem = problemRepository.findById(id) .orElseThrow(() -> new ApiException(ErrorType._PROBLEM_NOT_FOUND)); + + return ProblemConverter.convertToDto(bojProblem).orElseThrow(() -> new ApiException(ErrorType._PROBLEM_CONVERSION_ERROR)); } } \ No newline at end of file diff --git a/src/main/java/com/api/TaveShot/global/exception/ErrorType.java b/src/main/java/com/api/TaveShot/global/exception/ErrorType.java index d05d982..4f5b8c3 100644 --- a/src/main/java/com/api/TaveShot/global/exception/ErrorType.java +++ b/src/main/java/com/api/TaveShot/global/exception/ErrorType.java @@ -81,7 +81,8 @@ public enum ErrorType { // ------------------------------------------ Compile ------------------------------------------ _PROBLEM_NOT_FOUND(NOT_FOUND, "PROBLEM_4040", "요청한 문제 번호를 찾을 수 없습니다."), - _SUBMIT_PAGE_NOT_FOUND(NOT_FOUND, "COMPILE_4040", "아직 정답이 준비 되지 않아 코드를 제출할 수 없습니다.") + _SUBMIT_PAGE_NOT_FOUND(NOT_FOUND, "COMPILE_4040", "아직 정답이 준비 되지 않아 코드를 제출할 수 없습니다."), + _PROBLEM_CONVERSION_ERROR(INTERNAL_SERVER_ERROR, "PROBLEM_5002", "문제 정보 변환 중 오류가 발생했습니다.") ;