diff --git a/umbba-api/src/main/java/sopt/org/umbba/api/service/qna/QnAService.java b/umbba-api/src/main/java/sopt/org/umbba/api/service/qna/QnAService.java index 9f6846d5..a8c451cf 100644 --- a/umbba-api/src/main/java/sopt/org/umbba/api/service/qna/QnAService.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/service/qna/QnAService.java @@ -184,30 +184,14 @@ public List 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 qnaList = getQnAListByParentchild(parentchild); - - List opponentUserList = userRepository.findUserByParentChild(parentchild) - .stream() - .filter(user -> !user.getId().equals(userId)) - .collect(Collectors.toList()); + List 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