From bbe60fd27c35ec642d7392f4b8ddde6602729b4e Mon Sep 17 00:00:00 2001 From: JeonHaeseung <414catherine@gmail.com> Date: Tue, 4 Jun 2024 16:31:36 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[refact]=20=EB=A9=94=EC=9D=B8=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EB=B9=84=EB=8F=99=EA=B8=B0=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD(=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EB=8B=A8=EC=B6=95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ness/Backend/domain/main/MainService.java | 25 ++++++++++++++++--- .../Backend/domain/report/ReportService.java | 6 +++++ .../Ness/Backend/domain/todo/TodoService.java | 2 ++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/java/Ness/Backend/domain/main/MainService.java b/src/main/java/Ness/Backend/domain/main/MainService.java index 2929023..e40f13a 100644 --- a/src/main/java/Ness/Backend/domain/main/MainService.java +++ b/src/main/java/Ness/Backend/domain/main/MainService.java @@ -11,6 +11,8 @@ import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; @Service @RequiredArgsConstructor @@ -18,15 +20,32 @@ public class MainService { private final ReportService reportService; private final TodoService todoService; - public GetMainDto getMain(Long memberId){ - List scheduleDtos = todoService.getTodo(memberId); - PostFastApiAiRecommendActivityDto activityDtos = reportService.getRecommendActivity(memberId); + try { + CompletableFuture> scheduleFuture = CompletableFuture.supplyAsync(() -> todoService.getTodo(memberId)); + CompletableFuture activityFuture = CompletableFuture.supplyAsync(() -> reportService.getRecommendActivity(memberId)); + CompletableFuture combinedFuture = CompletableFuture.allOf(scheduleFuture, activityFuture); + + // 두 작업이 모두 완료될 때까지 기다린다.(각각 진행되는 것은 맞음, 가장 늦은 작업 완료에 맞춤) + combinedFuture.join(); + List scheduleDtos = scheduleFuture.get(); + PostFastApiAiRecommendActivityDto activityDtos = activityFuture.get(); + return toEntity(scheduleDtos, activityDtos); + } catch (Exception exception){ + List scheduleDtos = todoService.getTodo(memberId); + PostFastApiAiRecommendActivityDto activityDtos = reportService.getRecommendActivity(memberId); + return toEntity(scheduleDtos, activityDtos); + } + } + + //Entity -> DTO + public GetMainDto toEntity(List scheduleDtos, PostFastApiAiRecommendActivityDto activityDtos){ return GetMainDto.builder() .recommendText(activityDtos.getAnswer()) .activityList(activityDtos.getActivityList()) .scheduleList(scheduleDtos) .build(); } + } diff --git a/src/main/java/Ness/Backend/domain/report/ReportService.java b/src/main/java/Ness/Backend/domain/report/ReportService.java index 07aabcf..ec8af3d 100644 --- a/src/main/java/Ness/Backend/domain/report/ReportService.java +++ b/src/main/java/Ness/Backend/domain/report/ReportService.java @@ -40,6 +40,8 @@ public class ReportService { /* 메모리 가져오는 로직 */ public GetReportMemoryListDto getMemory(Long id){ + log.info("getMemory called by member: " + id); + // 오늘 날짜 가져오기 ZonedDateTime now = getToday(); @@ -94,6 +96,8 @@ public String postNewAiMemory(Long id, ZonedDateTime today){ /* 테그 가져오는 로직 */ public GetReportTagListDto getTag(Long id){ + log.info("getTag called by member: " + id); + // 오늘 날짜 가져오기 ZonedDateTime now = getToday(); @@ -150,6 +154,8 @@ public PostFastApiAiTagListDto postNewAiTag(Long id, ZonedDateTime today){ /* 한 줄 추천 및 엑티비티 가져오는 로직 */ public PostFastApiAiRecommendActivityDto getRecommendActivity(Long memberId){ + log.info("getRecommendActivity called by member: " + memberId); + // 오늘 날짜 가져오기 ZonedDateTime now = getToday(); List reportRecommends = reportRecommendRepository.findTodayReportRecommendByMember_Id(memberId); diff --git a/src/main/java/Ness/Backend/domain/todo/TodoService.java b/src/main/java/Ness/Backend/domain/todo/TodoService.java index 0bd3724..1e81cec 100644 --- a/src/main/java/Ness/Backend/domain/todo/TodoService.java +++ b/src/main/java/Ness/Backend/domain/todo/TodoService.java @@ -34,6 +34,8 @@ public class TodoService { /* 일정 관련 한 줄 추천 가져오는 로직 */ public List getTodo(Long memberId){ + log.info("getTodo called by member: " + memberId); + Profile userProfile = profileRepository.findProfileByMember_Id(memberId); // 오늘 날짜 가져오기 ZonedDateTime now = time.getToday(); From 3a75413168a9c3afa24ad7c98c9b7601bda3ddbc Mon Sep 17 00:00:00 2001 From: JeonHaeseung <414catherine@gmail.com> Date: Tue, 4 Jun 2024 16:32:52 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[chore]=20catch=20=EB=AC=B8=20=EC=A3=BC?= =?UTF-8?q?=EC=84=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Ness/Backend/domain/main/MainService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/Ness/Backend/domain/main/MainService.java b/src/main/java/Ness/Backend/domain/main/MainService.java index e40f13a..744ee97 100644 --- a/src/main/java/Ness/Backend/domain/main/MainService.java +++ b/src/main/java/Ness/Backend/domain/main/MainService.java @@ -32,7 +32,9 @@ public GetMainDto getMain(Long memberId){ PostFastApiAiRecommendActivityDto activityDtos = activityFuture.get(); return toEntity(scheduleDtos, activityDtos); - } catch (Exception exception){ + } + // 비동기 에러 발생시 동기 처리를 하더라도 메인 API 제공되도록 로직 설정 + catch (Exception exception){ List scheduleDtos = todoService.getTodo(memberId); PostFastApiAiRecommendActivityDto activityDtos = reportService.getRecommendActivity(memberId); return toEntity(scheduleDtos, activityDtos); From 4faf151b89f802098a43a61baade70bbac62dd8a Mon Sep 17 00:00:00 2001 From: JeonHaeseung <414catherine@gmail.com> Date: Tue, 4 Jun 2024 16:38:08 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[refact]=20=EA=B8=B0=EC=A1=B4=EC=97=90=20?= =?UTF-8?q?=EB=B9=88=20=EB=AC=B8=EC=9E=90=EC=97=B4=EB=A1=9C=20=EB=91=90?= =?UTF-8?q?=EC=97=88=EB=8D=98=20=ED=8E=98=EB=A5=B4=EC=86=8C=EB=82=98?= =?UTF-8?q?=EB=A5=BC=20=ED=95=AD=EC=83=81=20=EC=9C=A0=EC=A0=80=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=EC=97=90=EC=84=9C=20=EA=B0=80=EC=A0=B8?= =?UTF-8?q?=EC=98=A4=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Backend/domain/report/ReportService.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/Ness/Backend/domain/report/ReportService.java b/src/main/java/Ness/Backend/domain/report/ReportService.java index ec8af3d..079aa2e 100644 --- a/src/main/java/Ness/Backend/domain/report/ReportService.java +++ b/src/main/java/Ness/Backend/domain/report/ReportService.java @@ -2,6 +2,9 @@ import Ness.Backend.domain.member.MemberRepository; import Ness.Backend.domain.member.entity.Member; +import Ness.Backend.domain.profile.ProfileRepository; +import Ness.Backend.domain.profile.entity.PersonaType; +import Ness.Backend.domain.profile.entity.Profile; import Ness.Backend.domain.report.dto.request.PostFastApiUserMemoryDto; import Ness.Backend.domain.report.dto.request.PostFastApiUserRecommendActivityDto; import Ness.Backend.domain.report.dto.request.PostFastApiUserTagDto; @@ -37,6 +40,7 @@ public class ReportService { private final FastApiTagApi fastApiTagApi; private final FastApiMemoryApi fastApiMemoryApi; private final MemberRepository memberRepository; + private final ProfileRepository profileRepository; /* 메모리 가져오는 로직 */ public GetReportMemoryListDto getMemory(Long id){ @@ -81,9 +85,10 @@ public GetReportMemoryListDto createReportMemoryListDto(List repor } public String postNewAiMemory(Long id, ZonedDateTime today){ + String persona = getPersona(id); PostFastApiUserMemoryDto userDto = PostFastApiUserMemoryDto.builder() .member_id(id.intValue()) - .user_persona("") + .user_persona(persona) .schedule_datetime_start(today) .schedule_datetime_end(today) .build(); @@ -141,9 +146,10 @@ public PostFastApiAiTagListDto getAiTag(Long id){ } public PostFastApiAiTagListDto postNewAiTag(Long id, ZonedDateTime today){ + String persona = getPersona(id); PostFastApiUserTagDto userDto = PostFastApiUserTagDto.builder() .member_id(id.intValue()) - .user_persona("") + .user_persona(persona) .schedule_datetime_start(today) .schedule_datetime_end(today) .build(); @@ -210,9 +216,10 @@ public PostFastApiAiRecommendActivityDto getRecommendActivity(Long memberId){ } public PostFastApiAiRecommendActivityDto postNewAiRecommend(Long id, ZonedDateTime today){ + String persona = getPersona(id); PostFastApiUserRecommendActivityDto userDto = PostFastApiUserRecommendActivityDto.builder() .member_id(id.intValue()) - .user_persona("") // 빈 문자열은 default + .user_persona(persona) .schedule_datetime_start(today) .schedule_datetime_end(today) .build(); @@ -229,4 +236,19 @@ public ZonedDateTime getToday(){ return ZonedDateTime.now(ZoneId.of("Asia/Seoul")); } + public String getPersona(Long memberId){ + Profile profileEntity = profileRepository.findProfileByMember_Id(memberId); + PersonaType personaType = profileEntity.getPersonaType(); + + String persona = "default"; + if (personaType == PersonaType.HARDNESS){ + persona = "hard"; + } + if (personaType == PersonaType.CALMNESS){ + persona = "calm"; + } + + return persona; + } + } From 975d38c84c7ab5b54e3eb9cddf9fffa5e4d40d5b Mon Sep 17 00:00:00 2001 From: JeonHaeseung <414catherine@gmail.com> Date: Tue, 4 Jun 2024 16:42:57 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[chore]=20id=EC=9D=98=20=EB=B3=80=EC=88=98?= =?UTF-8?q?=EB=AA=85=EC=9D=84=20memberId=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Backend/domain/report/ReportService.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/java/Ness/Backend/domain/report/ReportService.java b/src/main/java/Ness/Backend/domain/report/ReportService.java index 079aa2e..c2b3071 100644 --- a/src/main/java/Ness/Backend/domain/report/ReportService.java +++ b/src/main/java/Ness/Backend/domain/report/ReportService.java @@ -43,19 +43,19 @@ public class ReportService { private final ProfileRepository profileRepository; /* 메모리 가져오는 로직 */ - public GetReportMemoryListDto getMemory(Long id){ - log.info("getMemory called by member: " + id); + public GetReportMemoryListDto getMemory(Long memberId){ + log.info("getMemory called by member: " + memberId); // 오늘 날짜 가져오기 ZonedDateTime now = getToday(); - ReportMemory reportMemory = reportMemoryRepository.findTodayReportMemoryByMember_Id(id); + ReportMemory reportMemory = reportMemoryRepository.findTodayReportMemoryByMember_Id(memberId); if (reportMemory == null){ // 오늘치가 없다면 새롭게 생성하기 - String memory = postNewAiMemory(id, now); + String memory = postNewAiMemory(memberId, now); - Member memberEntity = memberRepository.findMemberById(id); + Member memberEntity = memberRepository.findMemberById(memberId); ReportMemory newMemory = ReportMemory.builder() .createdDate(now) @@ -67,7 +67,7 @@ public GetReportMemoryListDto getMemory(Long id){ } // 2주치의 데이터 가져오기 - List reportMemories = reportMemoryRepository.findTwoWeekUserMemoryByMember_Id(id); + List reportMemories = reportMemoryRepository.findTwoWeekUserMemoryByMember_Id(memberId); return createReportMemoryListDto(reportMemories); } @@ -84,10 +84,10 @@ public GetReportMemoryListDto createReportMemoryListDto(List repor return new GetReportMemoryListDto(getReportMemoryDtos); } - public String postNewAiMemory(Long id, ZonedDateTime today){ - String persona = getPersona(id); + public String postNewAiMemory(Long memberId, ZonedDateTime today){ + String persona = getPersona(memberId); PostFastApiUserMemoryDto userDto = PostFastApiUserMemoryDto.builder() - .member_id(id.intValue()) + .member_id(memberId.intValue()) .user_persona(persona) .schedule_datetime_start(today) .schedule_datetime_end(today) @@ -100,18 +100,18 @@ public String postNewAiMemory(Long id, ZonedDateTime today){ } /* 테그 가져오는 로직 */ - public GetReportTagListDto getTag(Long id){ - log.info("getTag called by member: " + id); + public GetReportTagListDto getTag(Long memberId){ + log.info("getTag called by member: " + memberId); // 오늘 날짜 가져오기 ZonedDateTime now = getToday(); - List reportTags = reportTagRepository.findLastMonthReportTagByMember_Id(id); + List reportTags = reportTagRepository.findLastMonthReportTagByMember_Id(memberId); if (reportTags == null || reportTags.isEmpty()) { - PostFastApiAiTagListDto aiDto = postNewAiTag(id, getToday()); + PostFastApiAiTagListDto aiDto = postNewAiTag(memberId, getToday()); - Member memberEntity = memberRepository.findMemberById(id); + Member memberEntity = memberRepository.findMemberById(memberId); for (PostFastApiAiTagDto tag : aiDto.getTags()) { ReportTag reportTag = ReportTag.builder() @@ -122,7 +122,7 @@ public GetReportTagListDto getTag(Long id){ .build(); reportTagRepository.save(reportTag); } - return createReportTagListDto(reportTagRepository.findLastMonthReportTagByMember_Id(id)); + return createReportTagListDto(reportTagRepository.findLastMonthReportTagByMember_Id(memberId)); } else { return createReportTagListDto(reportTags); } @@ -141,14 +141,14 @@ public GetReportTagListDto createReportTagListDto(List reportTags){ return new GetReportTagListDto(getReportTagDtos); } - public PostFastApiAiTagListDto getAiTag(Long id){ - return postNewAiTag(id, getToday()); + public PostFastApiAiTagListDto getAiTag(Long memberId){ + return postNewAiTag(memberId, getToday()); } - public PostFastApiAiTagListDto postNewAiTag(Long id, ZonedDateTime today){ - String persona = getPersona(id); + public PostFastApiAiTagListDto postNewAiTag(Long memberId, ZonedDateTime today){ + String persona = getPersona(memberId); PostFastApiUserTagDto userDto = PostFastApiUserTagDto.builder() - .member_id(id.intValue()) + .member_id(memberId.intValue()) .user_persona(persona) .schedule_datetime_start(today) .schedule_datetime_end(today) @@ -215,10 +215,10 @@ public PostFastApiAiRecommendActivityDto getRecommendActivity(Long memberId){ } } - public PostFastApiAiRecommendActivityDto postNewAiRecommend(Long id, ZonedDateTime today){ - String persona = getPersona(id); + public PostFastApiAiRecommendActivityDto postNewAiRecommend(Long memberId, ZonedDateTime today){ + String persona = getPersona(memberId); PostFastApiUserRecommendActivityDto userDto = PostFastApiUserRecommendActivityDto.builder() - .member_id(id.intValue()) + .member_id(memberId.intValue()) .user_persona(persona) .schedule_datetime_start(today) .schedule_datetime_end(today)