Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(Problem): 문제 세트 조회 API 구현 (SWM-45) #8

Merged
merged 4 commits into from
Jun 25, 2024

Conversation

morenow98
Copy link
Member

PR 변경된 내용

  • 문제 조회 API 가 기존에 과목 ID를 하나만 받는 문제 수정
  • 문제 조회 시 examId는 required = false 이므로 깔끔한 처리를 위해 Optional로 요청받는 것으로 변경.
  • Problem Entity 구현
  • Problem에서 Exam과 Subject는 문제를 가져올 때마다 항상 가져와야 하기 때문에 FetchType.EAGER 로 설정. 가져오지 않는 경우의 존재 여부나 코드 스멜 등에서는 추후 논의
  • 문제 랜덤 조회 쿼리는 native query로 구현. RAND()을 jpql이나 jpa에서 지원하지 않기 때문. 하지만 성능이 좋지 않음. 추후 논의해야 할 쿼리
  • 이와 관련된 글 : https://dazbee.tistory.com/49
  • 조회 API와 관련한 테스트 코드 구현

추가 내용

참조

Jira Issue: SWM-45

- 문제 랜덤 조회 쿼리는 native query로 구현
- Problem에서 Exam과 Subject를 EAGER로 설정
- Problem의 Exception 관련 코드 구현
- UseCase에서 로직 구현에도 stream을 더욱 적극 활용하도록 변경
@morenow98 morenow98 requested a review from InHyeok-J June 25, 2024 07:58
@morenow98 morenow98 self-assigned this Jun 25, 2024
Comment on lines +46 to 56
return subjectIds.stream()
.map(subjectId -> {
if (examId.isPresent()) {
return problemRepository.findRandomByExamIdAndSubjectId(examId.get(), subjectId, count);
}
return problemRepository.findRandomBySubjectId(subjectId, count);
})
.flatMap(List::stream)
.map(FindProblemsResponse::from)
.toList();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

db 접근 로직이랑 / List 응답 맵핑 Stream을 분리할 수 없나요?

가독성 + 유지보수에 어려울 것 같아서요

Copy link
Member Author

@morenow98 morenow98 Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 수정했습니다~
다음 PR에 올릴게요~!

@morenow98 morenow98 changed the title Feat(Problem): 문제 세트 조회 API 구현 Feat(Problem): 문제 세트 조회 API 구현 (SWM-45) Jun 25, 2024
@morenow98 morenow98 merged commit 5dc4a6a into develop Jun 25, 2024
1 check passed
@morenow98 morenow98 deleted the feature/SWM-45-find-problem-set branch June 25, 2024 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants