diff --git a/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/TodayQnAResponseDto.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/TodayQnAResponseDto.java index 998d555b..d85beb0a 100644 --- a/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/TodayQnAResponseDto.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/qna/dto/response/TodayQnAResponseDto.java @@ -54,20 +54,37 @@ public static TodayQnAResponseDto of(User myUser, User opponentUser, int count, isMyAnswer = todayQnA.isParentAnswer(); } - return TodayQnAResponseDto.builder() - .qnaId(todayQnA.getId()) - .index(count) - .section(todayQuestion.getSection().getValue()) - .topic(todayQuestion.getTopic()) - .opponentQuestion(opponentQuestion) - .myQuestion(myQuestion) - .opponentAnswer(opponentAnswer) - .myAnswer(myAnswer) - .isOpponentAnswer(isOpponentAnswer) - .isMyAnswer(isMyAnswer) - .opponentUsername(opponentUser.getUsername()) - .myUsername(myUser.getUsername()) - .build(); + if (opponentUser != null) { + return TodayQnAResponseDto.builder() + .qnaId(todayQnA.getId()) + .index(count) + .section(todayQuestion.getSection().getValue()) + .topic(todayQuestion.getTopic()) + .opponentQuestion(opponentQuestion) + .myQuestion(myQuestion) + .opponentAnswer(opponentAnswer) + .myAnswer(myAnswer) + .isOpponentAnswer(isOpponentAnswer) + .isMyAnswer(isMyAnswer) + .opponentUsername(opponentUser.getUsername()) + .myUsername(myUser.getUsername()) + .build(); + } else { + return TodayQnAResponseDto.builder() + .qnaId(todayQnA.getId()) + .index(count) + .section(todayQuestion.getSection().getValue()) + .topic(todayQuestion.getTopic()) + .opponentQuestion(null) + .myQuestion(myQuestion) + .opponentAnswer(null) + .myAnswer(myAnswer) + .isOpponentAnswer(null) + .isMyAnswer(isMyAnswer) + .opponentUsername(null) + .myUsername(myUser.getUsername()) + .build(); + } } } 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 5bdf0e54..e466d215 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 @@ -55,9 +55,18 @@ public TodayQnAResponseDto getTodayQnA(Long userId) { Parentchild parentchild = getParentchildByUser(myUser); QnA todayQnA = getTodayQnAByParentchild(parentchild); Question todayQuestion = todayQnA.getQuestion(); - User opponentUser = getOpponentByParentchild(parentchild, userId); - return TodayQnAResponseDto.of(myUser, opponentUser, parentchild.getCount(), todayQnA, todayQuestion); + User opponentUser; + List opponentUserList = userRepository.findUserByParentChild(parentchild) + .stream() + .filter(user -> !user.getId().equals(userId)) + .collect(Collectors.toList()); + if (opponentUserList.isEmpty()) { + return TodayQnAResponseDto.of(myUser, null, parentchild.getCount(), todayQnA, todayQuestion); + } else { + opponentUser = opponentUserList.get(0); + return TodayQnAResponseDto.of(myUser, opponentUser, parentchild.getCount(), todayQnA, todayQuestion); + } } public GetInvitationResponseDto getInvitation(Long userId) {