From 278a10f13f685042118e1786e2f0cc2592d5ab59 Mon Sep 17 00:00:00 2001 From: jun02160 Date: Sat, 23 Mar 2024 17:30:02 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]=20=EA=B3=BC=EA=B1=B0=20QnA=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EB=A1=9C=EC=A7=81=20rollback=20#142?= 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, 4 insertions(+), 20 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 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