Skip to content

Commit

Permalink
[FEAT] 기존에 가까워지기 질문이 없던 유저도 사용할 수 있도록 변경 #137
Browse files Browse the repository at this point in the history
  • Loading branch information
ddongseop committed Mar 16, 2024
1 parent 22a24bf commit 194a512
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import sopt.org.umbba.domain.domain.user.User;
import sopt.org.umbba.domain.domain.user.repository.UserRepository;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -36,6 +37,10 @@ public TodayCloserQnAResponseDto getTodayCloserQnA(Long userId) {
throw new CustomException(ErrorType.USER_HAVE_NO_PARENTCHILD);
}

if (parentchild.getCloserQnaList().isEmpty()) {
addFirstCloserQnA(parentchild);
}

if (user.isMeChild()) {
int closerCount = parentchild.getCloserChildCount();
CloserQnA todayQnA = parentchild.getCloserQnaList().get(closerCount);
Expand All @@ -62,6 +67,20 @@ public TodayCloserQnAResponseDto getTodayCloserQnA(Long userId) {
}
}

@Transactional
public void addFirstCloserQnA(Parentchild parentchild) {
CloserQuestion firstCloserQuestion = closerQuestionRepository.findRandomExceptIds(new ArrayList<>())
.orElseThrow(() -> new CustomException(ErrorType.NOT_FOUND_CLOSER_QUESTION));

CloserQnA newCloserQnA = CloserQnA.builder()
.closerQuestion(firstCloserQuestion)
.isParentAnswer(false)
.isChildAnswer(false)
.build();
closerQnARepository.save(newCloserQnA);
parentchild.addCloserQna(newCloserQnA);
}

@Transactional
public void answerTodayCloserQnA(Long userId, TodayCloserAnswerRequestDto request) {
User user = getUserById(userId);
Expand Down

0 comments on commit 194a512

Please sign in to comment.