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

[CHORE] 튜토리얼 첫 번째 QnA 조회 로직 버그 해결 #141

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,30 @@ public List<QnAListResponseDto> getQnaList(Long userId, Long sectionId) {
public SingleQnAResponseDto getSingleQna(Long userId, Long qnaId) {
User myUser = getUserById(userId);
Parentchild parentchild = getParentchildByUser(myUser);

User opponentUser = getOpponentByParentchild(parentchild, userId);
QnA targetQnA = getQnAById(qnaId);
Question todayQuestion = targetQnA.getQuestion();

List<QnA> qnaList = getQnAListByParentchild(parentchild);

return SingleQnAResponseDto.of(myUser, opponentUser, qnaList.indexOf(targetQnA) + 1, targetQnA, todayQuestion);
List<User> opponentUserList = userRepository.findUserByParentChild(parentchild)
.stream()
.filter(user -> !user.getId().equals(userId))
.collect(Collectors.toList());


if (opponentUserList.isEmpty()) {
boolean isFirstQnA = qnaList.get(0).equals(targetQnA);

if (isFirstQnA) {
return SingleQnAResponseDto.of(myUser, null, 1, targetQnA, todayQuestion);
} else {
throw new CustomException(ErrorType.PARENTCHILD_HAVE_NO_OPPONENT);
}
}

int index = qnaList.indexOf(targetQnA) + 1;
User opponentUser = opponentUserList.get(0);

return SingleQnAResponseDto.of(myUser, opponentUser, index, targetQnA, todayQuestion);
}

@Transactional
Expand Down
Loading