From d5f094ce04991fbad31553353d862c7d9593bfa5 Mon Sep 17 00:00:00 2001 From: jun02160 Date: Wed, 20 Mar 2024 01:46:39 +0900 Subject: [PATCH] =?UTF-8?q?[CHORE]=20=ED=8A=9C=ED=86=A0=EB=A6=AC=EC=96=BC?= =?UTF-8?q?=20=EC=B2=AB=20=EB=B2=88=EC=A7=B8=20QnA=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EB=B2=84=EA=B7=B8=20=ED=95=B4=EA=B2=B0=20?= =?UTF-8?q?#140?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/umbba/api/service/qna/QnAService.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) 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 a8c451cf..9f6846d5 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,14 +184,30 @@ 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); - return SingleQnAResponseDto.of(myUser, opponentUser, qnaList.indexOf(targetQnA) + 1, targetQnA, todayQuestion); + List 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