Skip to content

Commit

Permalink
refactor: @requiredargsconstructor 추가, @Autowired 제거 (생성자 1개) (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonbinn committed Jan 24, 2024
1 parent 45906de commit b7d9a87
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProblemDto> getProblemById(String id) {
return problemRepository.findById(id)
.map(ProblemConverter::convertToDto)
.orElseThrow(() -> new ApiException(ErrorType._PROBLEM_NOT_FOUND));

return problemConverter.convertToDto(bojProblem);
}
}

0 comments on commit b7d9a87

Please sign in to comment.