Skip to content

Commit

Permalink
refactor: Optional에 맞춰 수정 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonbinn committed Jan 24, 2024
1 parent b7d9a87 commit 0619ee1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ public class CompilerController {
schema = @Schema(implementation = ProblemDto.class)))
})
@GetMapping("/problems/{id}")
public ResponseEntity<SuccessResponse<ProblemDto>> getProblem(@PathVariable String id) {
return problemService.getProblemById(id)
.map(problemDto -> ResponseEntity.ok(new SuccessResponse<>(problemDto)))
.orElseGet(() -> ResponseEntity.notFound().build());
public SuccessResponse<ProblemDto> getProblem(@PathVariable String id) {
ProblemDto problemDto = problemService.getProblemById(id);
return new SuccessResponse<>(problemDto);
}

/*@Operation(summary = "코드 컴파일링 및 채점", description = "해당 문제 풀이에 대한 채점 결과를 보여줍니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ public class ProblemService {

private final ProblemRepository problemRepository;

public Optional<ProblemDto> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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", "문제 정보 변환 중 오류가 발생했습니다.")

;

Expand Down

0 comments on commit 0619ee1

Please sign in to comment.