Skip to content

Commit

Permalink
Merge pull request #143 from Team-Umbba/fix/#142-single_qna_rollback
Browse files Browse the repository at this point in the history
[FIX] 과거 QnA 조회 로직 rollback
  • Loading branch information
jun02160 authored Mar 23, 2024
2 parents 694d790 + 278a10f commit db17b9a
Showing 1 changed file with 4 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,30 +184,14 @@ 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);

List<User> opponentUserList = userRepository.findUserByParentChild(parentchild)
.stream()
.filter(user -> !user.getId().equals(userId))
.collect(Collectors.toList());

List<QnA> qnaList = getQnAListByParentchild(parentchild);

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);
return SingleQnAResponseDto.of(myUser, opponentUser, qnaList.indexOf(targetQnA) + 1, targetQnA, todayQuestion);
}

@Transactional
Expand Down

0 comments on commit db17b9a

Please sign in to comment.