From 194a5123bb4c43298a4acce571023c3d2756eefe Mon Sep 17 00:00:00 2001 From: ddongseop Date: Sat, 16 Mar 2024 12:21:59 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20=EA=B8=B0=EC=A1=B4=EC=97=90=20?= =?UTF-8?q?=EA=B0=80=EA=B9=8C=EC=9B=8C=EC=A7=80=EA=B8=B0=20=EC=A7=88?= =?UTF-8?q?=EB=AC=B8=EC=9D=B4=20=EC=97=86=EB=8D=98=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EB=8F=84=20=EC=82=AC=EC=9A=A9=ED=95=A0=20=EC=88=98=20=EC=9E=88?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD=20#137?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/service/closer/CloserService.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/umbba-api/src/main/java/sopt/org/umbba/api/service/closer/CloserService.java b/umbba-api/src/main/java/sopt/org/umbba/api/service/closer/CloserService.java index f6d40e39..fbf8a27e 100644 --- a/umbba-api/src/main/java/sopt/org/umbba/api/service/closer/CloserService.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/service/closer/CloserService.java @@ -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; @@ -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); @@ -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);