From b7d9a877f1b860140f091cf976d29524fb14d8df Mon Sep 17 00:00:00 2001 From: hyeonbin Date: Wed, 24 Jan 2024 21:30:05 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20@RequiredArgsConstructor=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80,=20@Autowired=20=EC=A0=9C=EA=B1=B0=20(?= =?UTF-8?q?=EC=83=9D=EC=84=B1=EC=9E=90=201=EA=B0=9C)=20(#28)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compiler/service/ProblemService.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) 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