Skip to content

Commit

Permalink
Merge pull request #131 from Team-Umbba/fix/#130-today_qna_case_4
Browse files Browse the repository at this point in the history
[FIX] 튜토리얼 오늘의 질문 알 수 있도록 변경
  • Loading branch information
ddongseop authored Feb 27, 2024
2 parents a026abf + b8686e6 commit dceb65e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<User> 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) {
Expand Down

0 comments on commit dceb65e

Please sign in to comment.