diff --git a/src/main/java/sopt/org/umbbaServer/domain/parentchild/model/Parentchild.java b/src/main/java/sopt/org/umbbaServer/domain/parentchild/model/Parentchild.java index 4af04229..45f4a741 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/parentchild/model/Parentchild.java +++ b/src/main/java/sopt/org/umbbaServer/domain/parentchild/model/Parentchild.java @@ -26,6 +26,13 @@ public class Parentchild extends AuditingTimeEntity { @JoinColumn(name = "parentchild_id") private List qnaList; + @Column(nullable = false) + private int count; + + public void addCount() { + this.count += 1; + } + @Column(nullable = false) private String inviteCode; diff --git a/src/main/java/sopt/org/umbbaServer/domain/parentchild/service/ParentchildService.java b/src/main/java/sopt/org/umbbaServer/domain/parentchild/service/ParentchildService.java index 87b012b3..fbca1302 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/parentchild/service/ParentchildService.java +++ b/src/main/java/sopt/org/umbbaServer/domain/parentchild/service/ParentchildService.java @@ -52,6 +52,7 @@ public OnboardingInviteResponseDto onboardInvite(Long userId, OnboardingInviteRe .isInvitorChild(request.getIsInvitorChild()) .relation(getRelation(request.getUserInfo().getGender(), request.getRelationInfo(), request.getIsInvitorChild())) .pushTime(request.getPushTime()) // TODO 케이스에 따라 없을 수도 있음 + .count(1) .build(); parentchildRepository.save(parentchild); user.updateParentchild(parentchild); diff --git a/src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/response/TodayQnAResponseDto.java b/src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/response/TodayQnAResponseDto.java index 08fc299c..be1d374b 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/response/TodayQnAResponseDto.java +++ b/src/main/java/sopt/org/umbbaServer/domain/qna/controller/dto/response/TodayQnAResponseDto.java @@ -14,6 +14,7 @@ public class TodayQnAResponseDto { private Long qnaId; + private Integer index; private String section; private String topic; private String opponentQuestion; @@ -29,7 +30,7 @@ public class TodayQnAResponseDto { private String myUsername; - public static TodayQnAResponseDto of(User myUser, User opponentUser, QnA todayQnA, Question todayQuestion, boolean isMeChild) { + public static TodayQnAResponseDto of(User myUser, User opponentUser, int count, QnA todayQnA, Question todayQuestion) { String opponentQuestion; String myQuestion; String opponentAnswer; @@ -37,7 +38,7 @@ public static TodayQnAResponseDto of(User myUser, User opponentUser, QnA todayQn boolean isOpponentAnswer; boolean isMyAnswer; - if (isMeChild) { + if (myUser.isMeChild()) { opponentQuestion = todayQuestion.getParentQuestion(); myQuestion = todayQuestion.getChildQuestion(); opponentAnswer = todayQnA.getParentAnswer(); @@ -55,6 +56,7 @@ public static TodayQnAResponseDto of(User myUser, User opponentUser, QnA todayQn return TodayQnAResponseDto.builder() .qnaId(todayQnA.getId()) + .index(count) .section(todayQuestion.getSection().getValue()) .topic(todayQuestion.getTopic()) .opponentQuestion(opponentQuestion) @@ -67,7 +69,6 @@ public static TodayQnAResponseDto of(User myUser, User opponentUser, QnA todayQn .myUsername(myUser.getUsername()) .build(); } - } diff --git a/src/main/java/sopt/org/umbbaServer/domain/qna/service/QnAService.java b/src/main/java/sopt/org/umbbaServer/domain/qna/service/QnAService.java index 47997892..691b11d6 100644 --- a/src/main/java/sopt/org/umbbaServer/domain/qna/service/QnAService.java +++ b/src/main/java/sopt/org/umbbaServer/domain/qna/service/QnAService.java @@ -37,7 +37,6 @@ public class QnAService { private final QnARepository qnARepository; private final QuestionRepository questionRepository; private final UserRepository userRepository; - private final QnADao qnADao; private final ParentchildDao parentchildDao; private final FCMService fcmService; //TODO Service에서 Service를 주입받는 부분 수정 @@ -49,7 +48,7 @@ public TodayQnAResponseDto getTodayQnA(Long userId) { Question todayQuestion = todayQnA.getQuestion(); User opponentUser = getOpponentByParentchild(parentchild, userId); - return TodayQnAResponseDto.of(myUser, opponentUser, todayQnA, todayQuestion, myUser.isMeChild()); + return TodayQnAResponseDto.of(myUser, opponentUser, parentchild.getCount(), todayQnA, todayQuestion); } public GetInvitationResponseDto getInvitation(Long userId) { @@ -83,6 +82,12 @@ public void answerTodayQuestion(Long userId, TodayAnswerRequestDto request) { fcmService.pushOpponentReply(todayQnA.getQuestion().getChildQuestion(), opponentUser.getId()); } + // TODO 정해진 시간이 되었을 때 이부분을 호출하도록 예준이가 하기 +// if (todayQnA.isParentAnswer() && todayQnA.isChildAnswer()) { +// // 다음날 질문으로 넘어감 +// parentchild.addCount(); +// } + } public List getQnaList(Long userId, Long sectionId) { @@ -220,7 +225,7 @@ private QnA getTodayQnAByParentchild(Parentchild parentchild) { throw new CustomException(ErrorType.PARENTCHILD_HAVE_NO_QNALIST); } - return qnAList.get(qnAList.size() - 1); // 가장 최근의 QnA를 가져옴 + return qnAList.get(parentchild.getCount() - 1); // 가장 최근의 QnA를 가져옴 } private QnA getQnAById(Long qnaId) { @@ -265,16 +270,19 @@ private QuestionType selectType(List childList, List qnAList = getQnAListByParentchild(parentchild); - List qnAList = qnADao.findQnASByUserId(userId).orElseThrow( - () -> new CustomException(ErrorType.USER_HAVE_NO_QNALIST) - ); - QnA lastQna = qnAList.get(qnAList.size()-1); + QnA lastQna = qnAList.get(parentchild.getCount() - 1); - return GetMainViewResponseDto.of(lastQna, qnAList.size()); + return GetMainViewResponseDto.of(lastQna, parentchild.getCount()); } private GetInvitationResponseDto invitation(Long userId) {