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 a9430ed..a57430a 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 @@ -6,26 +6,22 @@ import com.api.TaveShot.domain.compiler.repository.ProblemRepository; import com.api.TaveShot.global.exception.ApiException; import com.api.TaveShot.global.exception.ErrorType; +import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Optional; + @Service +@RequiredArgsConstructor public class ProblemService { private final ProblemRepository problemRepository; - private final ProblemConverter problemConverter; - - @Autowired - public ProblemService(ProblemRepository problemRepository, ProblemConverter problemConverter) { - this.problemRepository = problemRepository; - this.problemConverter = problemConverter; - } - public ProblemDto getProblemById(String id) { - BojProblem bojProblem = problemRepository.findById(id) + public Optional getProblemById(String id) { + return problemRepository.findById(id) + .map(ProblemConverter::convertToDto) .orElseThrow(() -> new ApiException(ErrorType._PROBLEM_NOT_FOUND)); - - return problemConverter.convertToDto(bojProblem); } } \ No newline at end of file