Skip to content

Commit

Permalink
Merge pull request #53 from Team-Umbba/feat/#52-add_current_count_field
Browse files Browse the repository at this point in the history
[FEAT] 지금 몇일차 질문에 대해 문답을 나누고 있는지 저장하는 필드 추가
  • Loading branch information
ddongseop authored Jul 17, 2023
2 parents 5e1562d + 2896c34 commit 4652e38
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public class Parentchild extends AuditingTimeEntity {
@JoinColumn(name = "parentchild_id")
private List<QnA> qnaList;

@Column(nullable = false)
private int count;

public void addCount() {
this.count += 1;
}

@Column(nullable = false)
private String inviteCode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class TodayQnAResponseDto {

private Long qnaId;
private Integer index;
private String section;
private String topic;
private String opponentQuestion;
Expand All @@ -29,15 +30,15 @@ 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;
String myAnswer;
boolean isOpponentAnswer;
boolean isMyAnswer;

if (isMeChild) {
if (myUser.isMeChild()) {
opponentQuestion = todayQuestion.getParentQuestion();
myQuestion = todayQuestion.getChildQuestion();
opponentAnswer = todayQnA.getParentAnswer();
Expand All @@ -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)
Expand All @@ -67,7 +69,6 @@ public static TodayQnAResponseDto of(User myUser, User opponentUser, QnA todayQn
.myUsername(myUser.getUsername())
.build();
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -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를 주입받는 부분 수정

Expand All @@ -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) {
Expand Down Expand Up @@ -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<QnAListResponseDto> getQnaList(Long userId, Long sectionId) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -265,16 +270,19 @@ private QuestionType selectType(List<OnboardingAnswer> childList, List<Onboardin
return TYPE7;
}

/*
리팩토링을 위해 아래로 뺀 메서드들 끝
*/

// 메인페이지 정보
public GetMainViewResponseDto getMainInfo(Long userId) {

Parentchild parentchild = getParentchildByUserId(userId);
List<QnA> qnAList = getQnAListByParentchild(parentchild);

List<QnA> 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) {
Expand Down

0 comments on commit 4652e38

Please sign in to comment.