Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] 튜토리얼 오늘의 질문 알 수 있도록 변경 #131

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 이 부분 예외처리가 걸려 있었군요.. 해결 감사합니다 !!!

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
Loading