Skip to content

Commit

Permalink
Merge pull request #141 from Team-Umbba/fix/#140-tutorial_bug_fix
Browse files Browse the repository at this point in the history
[CHORE] 튜토리얼 첫 번째 QnA 조회 로직 버그 해결
  • Loading branch information
ddongseop authored Mar 20, 2024
2 parents 0caa8a2 + d5f094c commit 694d790
Showing 1 changed file with 20 additions and 4 deletions.
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

0 comments on commit 694d790

Please sign in to comment.