From e31ccd8d18b24ab73b010f2e03955b261f9fc767 Mon Sep 17 00:00:00 2001 From: Kwon770 Date: Sat, 27 Apr 2024 01:54:40 +0900 Subject: [PATCH 1/6] feat: Divide getCalendar API to getMonthlyCalendar and getDailyCalendar And Impl getDailyCalendar --- .../java/com/oing/service/MemberBridge.java | 4 ++ .../java/com/oing/service/MissionBridge.java | 4 ++ .../oing/controller/CalendarController.java | 52 ++++++++++++++----- .../java/com/oing/restapi/CalendarApi.java | 16 +++++- .../com/oing/service/MemberBridgeImpl.java | 9 ++++ .../com/oing/service/MissionBridgeImpl.java | 5 ++ .../controller/CalendarControllerTest.java | 6 +-- .../java/com/oing/service/MissionService.java | 10 ++++ .../dto/response/DailyCalendarResponse.java | 31 +++++++++++ ...onse.java => MonthlyCalendarResponse.java} | 4 +- 10 files changed, 120 insertions(+), 21 deletions(-) create mode 100644 post/src/main/java/com/oing/dto/response/DailyCalendarResponse.java rename post/src/main/java/com/oing/dto/response/{CalendarResponse.java => MonthlyCalendarResponse.java} (90%) diff --git a/common/src/main/java/com/oing/service/MemberBridge.java b/common/src/main/java/com/oing/service/MemberBridge.java index 7ad3ec4b..b359b4dc 100644 --- a/common/src/main/java/com/oing/service/MemberBridge.java +++ b/common/src/main/java/com/oing/service/MemberBridge.java @@ -1,5 +1,7 @@ package com.oing.service; +import java.util.List; + /** * no5ing-server * User: CChuYong @@ -31,4 +33,6 @@ public interface MemberBridge { * @return 삭제된 사용자인지 여부 */ boolean isDeletedMember(String memberId); + + List getFamilyMembersIdsByFamilyId(String familyId); } diff --git a/common/src/main/java/com/oing/service/MissionBridge.java b/common/src/main/java/com/oing/service/MissionBridge.java index b7367e0c..75fd79fb 100644 --- a/common/src/main/java/com/oing/service/MissionBridge.java +++ b/common/src/main/java/com/oing/service/MissionBridge.java @@ -1,8 +1,12 @@ package com.oing.service; +import java.time.LocalDate; + public interface MissionBridge { String getContentByMissionId(String missionId); + String getContentByDate(LocalDate date); + String getTodayMissionId(); } diff --git a/gateway/src/main/java/com/oing/controller/CalendarController.java b/gateway/src/main/java/com/oing/controller/CalendarController.java index b16dec9e..03e13e96 100644 --- a/gateway/src/main/java/com/oing/controller/CalendarController.java +++ b/gateway/src/main/java/com/oing/controller/CalendarController.java @@ -3,14 +3,9 @@ import com.oing.domain.BannerImageType; import com.oing.domain.Post; import com.oing.domain.PostType; -import com.oing.dto.response.ArrayResponse; -import com.oing.dto.response.BannerResponse; -import com.oing.dto.response.CalendarResponse; -import com.oing.dto.response.FamilyMonthlyStatisticsResponse; +import com.oing.dto.response.*; import com.oing.restapi.CalendarApi; -import com.oing.service.FamilyService; -import com.oing.service.MemberService; -import com.oing.service.PostService; +import com.oing.service.*; import com.oing.util.OptimizedImageUrlGenerator; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Controller; @@ -18,12 +13,19 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; import java.util.List; +import java.util.stream.Collectors; @Controller @RequiredArgsConstructor public class CalendarController implements CalendarApi { + private final PostController postController; + private final MissionBridge missionBridge; + private final MemberBridge memberBridge; + private final MemberService memberService; private final PostService postService; private final FamilyService familyService; @@ -32,19 +34,40 @@ public class CalendarController implements CalendarApi { @Override - public ArrayResponse getMonthlyCalendar(String yearMonth, String familyId) { + public ArrayResponse getDailyCalendar(String yearMonthDay, String loginMemberId) { + List dailyCalendarResponses = new ArrayList<>(); + LocalDate date = LocalDate.parse(yearMonthDay, DateTimeFormatter.ISO_DATE); + + String missionContent = missionBridge.getContentByDate(date); + Collection survivalPosts = postController.fetchDailyFeeds(1, 10, date, loginMemberId, "ASC", PostType.SURVIVAL, loginMemberId, true).results(); + Collection missionPosts = postController.fetchDailyFeeds(1, 10, date, loginMemberId, "ASC", PostType.SURVIVAL, loginMemberId, true).results(); + + HashSet uploadedFamilyMembers = survivalPosts.stream().map(PostResponse::authorId).collect(Collectors.toCollection(HashSet::new)); + List familyMembersIds = memberBridge.getFamilyMembersIdsByFamilyId(loginMemberId); + boolean allFamilyMembersUploaded = uploadedFamilyMembers.containsAll(familyMembersIds); + + survivalPosts.forEach(post -> dailyCalendarResponses.add(new DailyCalendarResponse(date, PostType.SURVIVAL, post.postId(), post.imageUrl(), missionContent, allFamilyMembersUploaded))); + missionPosts.forEach(post -> dailyCalendarResponses.add(new DailyCalendarResponse(date, PostType.SURVIVAL, post.postId(), post.imageUrl(), missionContent, allFamilyMembersUploaded))); + + + return null; + } + + + @Override + public ArrayResponse getMonthlyCalendar(String yearMonth, String familyId) { if (yearMonth == null) yearMonth = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM")); LocalDate startDate = LocalDate.parse(yearMonth + "-01"); // yyyy-MM-dd 패턴으로 파싱 LocalDate endDate = startDate.plusMonths(1); List daysLatestPosts = postService.findLatestPostOfEveryday(startDate, endDate, familyId); - List calendarResponses = convertToCalendarResponse(daysLatestPosts, familyId); - return new ArrayResponse<>(calendarResponses); + List monthlyCalendarRespons = convertToCalendarResponse(daysLatestPosts, familyId); + return new ArrayResponse<>(monthlyCalendarRespons); } - private List convertToCalendarResponse(List daysLatestPosts, String familyId) { - List calendarResponses = new ArrayList<>(); + private List convertToCalendarResponse(List daysLatestPosts, String familyId) { + List monthlyCalendarRespons = new ArrayList<>(); for (Post dayLatestPost : daysLatestPosts) { LocalDate postDate = dayLatestPost.getCreatedAt().toLocalDate(); @@ -60,14 +83,14 @@ private List convertToCalendarResponse(List daysLatestPo } } - calendarResponses.add(new CalendarResponse( + monthlyCalendarRespons.add(new MonthlyCalendarResponse( dayLatestPost.getCreatedAt().toLocalDate(), dayLatestPost.getId(), optimizedImageUrlGenerator.getThumbnailUrlGenerator(dayLatestPost.getPostImgUrl()), allFamilyMembersUploaded )); } - return calendarResponses; + return monthlyCalendarRespons; } @@ -162,6 +185,7 @@ private BannerImageType getBannerImageType(int familyLevel) { return bannerImageType; } + @Override public FamilyMonthlyStatisticsResponse getSummary(String yearMonth, String loginMemberId) { String[] yearMonthArray = yearMonth.split("-"); diff --git a/gateway/src/main/java/com/oing/restapi/CalendarApi.java b/gateway/src/main/java/com/oing/restapi/CalendarApi.java index bd3c44a1..dabdb110 100644 --- a/gateway/src/main/java/com/oing/restapi/CalendarApi.java +++ b/gateway/src/main/java/com/oing/restapi/CalendarApi.java @@ -21,13 +21,25 @@ @RequestMapping("/v1/calendar") public interface CalendarApi { - @Operation(summary = "월별 캘린더 조회", description = "월별로 캘린더를 조회합니다. 각 날짜의 대표 게시글 정보와 가족 구성원 전부의 업로드 여부가가 조회되며, 해당 날짜에 게시글이 있는 경우만 response 에 포함됩니다.") + @Operation(summary = "월간 캘린더 조회", description = "월간 캘린더를 조회합니다. 각 날짜의 대표 게시글 정보와 가족 구성원 전부의 업로드 여부가가 조회되며, 해당 날짜에 게시글이 있는 경우만 response 에 포함됩니다.") @GetMapping(params = {"type=MONTHLY"}) - ArrayResponse getMonthlyCalendar( + ArrayResponse getMonthlyCalendar( @RequestParam @Parameter(description = "조회할 년월", example = "2021-12") String yearMonth, + @Parameter(hidden = true) + @LoginMemberId + String loginMemberId + ); + + @Operation(summary = "일간 캘린더 조회", description = "일간 캘린더를 조회합니다. 주어진 날에 업로드된 게시글들이 조회되며 정책에 따라, 게시일자 오름차순 / 생존신고 게시글 → 미션 게시글 순서로 정렬됩니다.") + @GetMapping(params = {"type=DAILY"}) + ArrayResponse getDailyCalendar( + @RequestParam + @Parameter(description = "조회할 년월일", example = "2021-12-25") + String yearMonthDay, + @Parameter(hidden = true) @LoginFamilyId String loginFamilyId diff --git a/gateway/src/main/java/com/oing/service/MemberBridgeImpl.java b/gateway/src/main/java/com/oing/service/MemberBridgeImpl.java index 5ab3f495..c36287c4 100644 --- a/gateway/src/main/java/com/oing/service/MemberBridgeImpl.java +++ b/gateway/src/main/java/com/oing/service/MemberBridgeImpl.java @@ -8,6 +8,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.List; + /** * no5ing-server * User: CChuYong @@ -48,4 +50,11 @@ public boolean isInSameFamily(String memberIdFirst, String memberIdSecond) { public boolean isDeletedMember(String memberId) { return memberRepository.existsByIdAndDeletedAtNotNull(memberId); } + + @Override + public List getFamilyMembersIdsByFamilyId(String familyId) { + return memberRepository.findAllByFamilyIdAndDeletedAtIsNull(familyId).stream() + .map(Member::getId) + .toList(); + } } diff --git a/gateway/src/main/java/com/oing/service/MissionBridgeImpl.java b/gateway/src/main/java/com/oing/service/MissionBridgeImpl.java index e88d5049..f62823d2 100644 --- a/gateway/src/main/java/com/oing/service/MissionBridgeImpl.java +++ b/gateway/src/main/java/com/oing/service/MissionBridgeImpl.java @@ -19,6 +19,11 @@ public String getContentByMissionId(String missionId) { return missionService.getMissionByMissionId(missionId).getContent(); } + @Override + public String getContentByDate(LocalDate date) { + return missionService.getMissionByDate(date).content(); + } + @Override public String getTodayMissionId() { LocalDate today = ZonedDateTime.now().toLocalDate(); diff --git a/gateway/src/test/java/com/oing/controller/CalendarControllerTest.java b/gateway/src/test/java/com/oing/controller/CalendarControllerTest.java index 64d3324d..9d744afb 100644 --- a/gateway/src/test/java/com/oing/controller/CalendarControllerTest.java +++ b/gateway/src/test/java/com/oing/controller/CalendarControllerTest.java @@ -4,7 +4,7 @@ import com.oing.domain.Post; import com.oing.domain.PostType; import com.oing.dto.response.ArrayResponse; -import com.oing.dto.response.CalendarResponse; +import com.oing.dto.response.MonthlyCalendarResponse; import com.oing.service.MemberService; import com.oing.service.PostService; import com.oing.util.OptimizedImageUrlGenerator; @@ -111,11 +111,11 @@ class CalendarControllerTest { when(postService.findLatestPostOfEveryday(startDate, endDate, familyId)).thenReturn(representativePosts); // When - ArrayResponse weeklyCalendar = calendarController.getMonthlyCalendar(yearMonth, familyId); + ArrayResponse weeklyCalendar = calendarController.getMonthlyCalendar(yearMonth, familyId); // Then assertThat(weeklyCalendar.results()) - .extracting(CalendarResponse::representativePostId) + .extracting(MonthlyCalendarResponse::representativePostId) .containsExactly("1", "2", "3", "4"); } } diff --git a/mission/src/main/java/com/oing/service/MissionService.java b/mission/src/main/java/com/oing/service/MissionService.java index 3eeb4b6e..f9b55785 100644 --- a/mission/src/main/java/com/oing/service/MissionService.java +++ b/mission/src/main/java/com/oing/service/MissionService.java @@ -10,12 +10,16 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.time.LocalDate; + @Slf4j @Service @RequiredArgsConstructor public class MissionService { private final MissionRepository missionRepository; + private final DailyMissionHistoryService dailyMissionHistoryService; + private final IdentityGenerator identityGenerator; @@ -41,6 +45,12 @@ public Mission getMissionByMissionId(String missionId) { // .orElseThrow(MissionNotFoundException::new); } + public MissionResponse getMissionByDate(LocalDate date) { + Mission mission = dailyMissionHistoryService.getDailyMissionHistoryByDate(date).getMission(); + + return MissionResponse.from(mission); + } + @Transactional public void updateMission(String missionId, CreateMissionRequest request) { diff --git a/post/src/main/java/com/oing/dto/response/DailyCalendarResponse.java b/post/src/main/java/com/oing/dto/response/DailyCalendarResponse.java new file mode 100644 index 00000000..1e512527 --- /dev/null +++ b/post/src/main/java/com/oing/dto/response/DailyCalendarResponse.java @@ -0,0 +1,31 @@ +package com.oing.dto.response; + +import com.oing.domain.PostType; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDate; + +@Schema(description = "일간 캘린더 응답") +public record DailyCalendarResponse( + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) + @Parameter(description = "오늘의 날짜", example = "2023-12-05") + LocalDate date, + + @Schema(description = "게시글 유형", example = "SURVIVAL") + PostType type, + + @Schema(description = "게시글 ID", example = "01HGW2N7EHJVJ4CJ999RRS2E97") + String postId, + + @Schema(description = "게시글 사진 url", example = "https://j1ansx15683.edge.naverncp.com/image/absc45j/image.jpg?type=f&w=96&h=96") + String postImgUrl, + + @Schema(description = "미션 내용 (생존신고 게시글이랑 null 반환)", example = "오늘의 기분을 나타내는 사진 찍기.") + String missionContent, + + @Schema(description = "모든 가족 구성원이 업로드 했는지 여부", example = "true") + boolean allFamilyMembersUploaded +) { +} diff --git a/post/src/main/java/com/oing/dto/response/CalendarResponse.java b/post/src/main/java/com/oing/dto/response/MonthlyCalendarResponse.java similarity index 90% rename from post/src/main/java/com/oing/dto/response/CalendarResponse.java rename to post/src/main/java/com/oing/dto/response/MonthlyCalendarResponse.java index f87c4db3..ac61cb89 100644 --- a/post/src/main/java/com/oing/dto/response/CalendarResponse.java +++ b/post/src/main/java/com/oing/dto/response/MonthlyCalendarResponse.java @@ -6,8 +6,8 @@ import java.time.LocalDate; -@Schema(description = "캘린더 응답") -public record CalendarResponse( +@Schema(description = "월간 캘린더 응답") +public record MonthlyCalendarResponse( @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) @Parameter(description = "오늘의 날짜", example = "2023-12-05") LocalDate date, From 6ddf8576c870c3f3b0daeb2fcf2a78dcbd7c1832 Mon Sep 17 00:00:00 2001 From: Kwon770 Date: Sat, 27 Apr 2024 02:46:13 +0900 Subject: [PATCH 2/6] fix: Add CalendarAPI test code for getDailyCalendar and fix the bug found by test code --- .../oing/controller/CalendarController.java | 19 +- .../java/com/oing/restapi/CalendarApi.java | 26 +-- .../controller/CalendarControllerTest.java | 2 +- .../com/oing/restapi/CalendarApiTest.java | 171 +++++++++++++++++- .../java/com/oing/service/MissionService.java | 7 +- 5 files changed, 199 insertions(+), 26 deletions(-) diff --git a/gateway/src/main/java/com/oing/controller/CalendarController.java b/gateway/src/main/java/com/oing/controller/CalendarController.java index 03e13e96..3ab7bd44 100644 --- a/gateway/src/main/java/com/oing/controller/CalendarController.java +++ b/gateway/src/main/java/com/oing/controller/CalendarController.java @@ -34,23 +34,24 @@ public class CalendarController implements CalendarApi { @Override - public ArrayResponse getDailyCalendar(String yearMonthDay, String loginMemberId) { + public ArrayResponse getDailyCalendar(String yearMonthDay, String loginMemberId, String loginFamilyId) { List dailyCalendarResponses = new ArrayList<>(); LocalDate date = LocalDate.parse(yearMonthDay, DateTimeFormatter.ISO_DATE); + Collection survivalPosts = postController.fetchDailyFeeds(1, 10, date, null, "ASC", PostType.SURVIVAL, loginMemberId, true).results(); + Collection missionPosts = postController.fetchDailyFeeds(1, 10, date, null, "ASC", PostType.MISSION, loginMemberId, true).results(); String missionContent = missionBridge.getContentByDate(date); - Collection survivalPosts = postController.fetchDailyFeeds(1, 10, date, loginMemberId, "ASC", PostType.SURVIVAL, loginMemberId, true).results(); - Collection missionPosts = postController.fetchDailyFeeds(1, 10, date, loginMemberId, "ASC", PostType.SURVIVAL, loginMemberId, true).results(); HashSet uploadedFamilyMembers = survivalPosts.stream().map(PostResponse::authorId).collect(Collectors.toCollection(HashSet::new)); - List familyMembersIds = memberBridge.getFamilyMembersIdsByFamilyId(loginMemberId); + System.out.println(uploadedFamilyMembers.toString()); + List familyMembersIds = memberBridge.getFamilyMembersIdsByFamilyId(loginFamilyId); + System.out.println(familyMembersIds.toString()); boolean allFamilyMembersUploaded = uploadedFamilyMembers.containsAll(familyMembersIds); + System.out.println(allFamilyMembersUploaded); - survivalPosts.forEach(post -> dailyCalendarResponses.add(new DailyCalendarResponse(date, PostType.SURVIVAL, post.postId(), post.imageUrl(), missionContent, allFamilyMembersUploaded))); - missionPosts.forEach(post -> dailyCalendarResponses.add(new DailyCalendarResponse(date, PostType.SURVIVAL, post.postId(), post.imageUrl(), missionContent, allFamilyMembersUploaded))); - - - return null; + survivalPosts.forEach(post -> dailyCalendarResponses.add(new DailyCalendarResponse(date, PostType.SURVIVAL, post.postId(), post.imageUrl(), null, allFamilyMembersUploaded))); + missionPosts.forEach(post -> dailyCalendarResponses.add(new DailyCalendarResponse(date, PostType.MISSION, post.postId(), post.imageUrl(), missionContent, allFamilyMembersUploaded))); + return ArrayResponse.of(dailyCalendarResponses); } diff --git a/gateway/src/main/java/com/oing/restapi/CalendarApi.java b/gateway/src/main/java/com/oing/restapi/CalendarApi.java index dabdb110..de6aa6c6 100644 --- a/gateway/src/main/java/com/oing/restapi/CalendarApi.java +++ b/gateway/src/main/java/com/oing/restapi/CalendarApi.java @@ -21,24 +21,28 @@ @RequestMapping("/v1/calendar") public interface CalendarApi { - @Operation(summary = "월간 캘린더 조회", description = "월간 캘린더를 조회합니다. 각 날짜의 대표 게시글 정보와 가족 구성원 전부의 업로드 여부가가 조회되며, 해당 날짜에 게시글이 있는 경우만 response 에 포함됩니다.") - @GetMapping(params = {"type=MONTHLY"}) - ArrayResponse getMonthlyCalendar( + @Operation(summary = "일간 캘린더 조회", description = "일간 캘린더를 조회합니다. 주어진 날에 업로드된 게시글들이 조회되며 정책에 따라, 게시일자 오름차순 / 생존신고 게시글 → 미션 게시글 순서로 정렬됩니다.") + @GetMapping(params = {"type=DAILY"}) + ArrayResponse getDailyCalendar( @RequestParam - @Parameter(description = "조회할 년월", example = "2021-12") - String yearMonth, + @Parameter(description = "조회할 년월일", example = "2021-12-25") + String yearMonthDay, @Parameter(hidden = true) @LoginMemberId - String loginMemberId + String loginMemberId, + + @Parameter(hidden = true) + @LoginFamilyId + String loginFamilyId ); - @Operation(summary = "일간 캘린더 조회", description = "일간 캘린더를 조회합니다. 주어진 날에 업로드된 게시글들이 조회되며 정책에 따라, 게시일자 오름차순 / 생존신고 게시글 → 미션 게시글 순서로 정렬됩니다.") - @GetMapping(params = {"type=DAILY"}) - ArrayResponse getDailyCalendar( + @Operation(summary = "월간 캘린더 조회", description = "월간 캘린더를 조회합니다. 각 날짜의 대표 게시글 정보와 가족 구성원 전부의 업로드 여부가가 조회되며, 해당 날짜에 게시글이 있는 경우만 response 에 포함됩니다.") + @GetMapping(params = {"type=MONTHLY"}) + ArrayResponse getMonthlyCalendar( @RequestParam - @Parameter(description = "조회할 년월일", example = "2021-12-25") - String yearMonthDay, + @Parameter(description = "조회할 년월", example = "2021-12") + String yearMonth, @Parameter(hidden = true) @LoginFamilyId diff --git a/gateway/src/test/java/com/oing/controller/CalendarControllerTest.java b/gateway/src/test/java/com/oing/controller/CalendarControllerTest.java index 9d744afb..472ffea8 100644 --- a/gateway/src/test/java/com/oing/controller/CalendarControllerTest.java +++ b/gateway/src/test/java/com/oing/controller/CalendarControllerTest.java @@ -60,7 +60,7 @@ class CalendarControllerTest { @Test - void 월별_캘린더_조회_테스트() { + void 월간_캘린더_조회_테스트() { // Given String yearMonth = "2023-11"; String familyId = testMember1.getFamilyId(); diff --git a/gateway/src/test/java/com/oing/restapi/CalendarApiTest.java b/gateway/src/test/java/com/oing/restapi/CalendarApiTest.java index 86ee78fd..a1529f98 100644 --- a/gateway/src/test/java/com/oing/restapi/CalendarApiTest.java +++ b/gateway/src/test/java/com/oing/restapi/CalendarApiTest.java @@ -3,7 +3,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.oing.config.support.OptimizedImageUrlProvider; import com.oing.domain.CreateNewUserDTO; +import com.oing.domain.Mission; import com.oing.domain.SocialLoginProvider; +import com.oing.dto.request.CreateMissionRequest; import com.oing.dto.request.JoinFamilyRequest; import com.oing.dto.response.DeepLinkResponse; import com.oing.dto.response.FamilyResponse; @@ -20,8 +22,10 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -49,6 +53,10 @@ class CalendarApiTest { @Autowired private PostService postService; @Autowired + private MissionService missionService; + @Autowired + private DailyMissionHistoryService dailyMissionHistoryService; + @Autowired private FamilyService familyService; @Autowired private DeepLinkService deepLinkService; @@ -126,8 +134,165 @@ void setUp() throws Exception { } + /* + * 주어진 날의 게시글만 불러오는가? + * 업로드날 짜 오름차순, 생존 게시물 미션 게시글 순서로 정렬되는가? + */ + @Test + void 일간_캘린더_조회_테스트() throws Exception { + // Given + // parameterss + String yearMonthDay = "2023-11-02"; + + // posts + jdbcTemplate.update("insert into post (post_id, member_id, family_id, mission_id, type, post_img_url, comment_cnt, reaction_cnt, created_at, updated_at, content, post_img_key) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + "1", TEST_MEMBER1_ID, TEST_FAMILY_ID, 1, "SURVIVAL", "https://storage.com/images/1", 0, 0, "2023-11-01 14:00:00", "2023-11-02 14:00:00", "post1111", "1"); + jdbcTemplate.update("insert into post (post_id, member_id, family_id, mission_id, type, post_img_url, comment_cnt, reaction_cnt, created_at, updated_at, content, post_img_key) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + "2", TEST_MEMBER2_ID, TEST_FAMILY_ID, 1, "SURVIVAL", "https://storage.com/images/2", 0, 0, "2023-11-01 15:00:00", "2023-11-02 15:00:00", "post2222", "2"); + jdbcTemplate.update("insert into post (post_id, member_id, family_id, mission_id, type, post_img_url, comment_cnt, reaction_cnt, created_at, updated_at, content, post_img_key) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + "3", TEST_MEMBER1_ID, TEST_FAMILY_ID, 1, "SURVIVAL", "https://storage.com/images/3", 0, 0, "2023-11-02 14:00:00", "2023-11-02 14:00:00", "post1111", "1"); + jdbcTemplate.update("insert into post (post_id, member_id, family_id, mission_id, type, post_img_url, comment_cnt, reaction_cnt, created_at, updated_at, content, post_img_key) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + "4", TEST_MEMBER2_ID, TEST_FAMILY_ID, 1, "SURVIVAL", "https://storage.com/images/4", 0, 0, "2023-11-02 15:00:00", "2023-11-02 15:00:00", "post2222", "2"); + jdbcTemplate.update("insert into post (post_id, member_id, family_id, mission_id, type, post_img_url, comment_cnt, reaction_cnt, created_at, updated_at, content, post_img_key) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + "5", TEST_MEMBER1_ID, TEST_FAMILY_ID, 1, "SURVIVAL", "https://storage.com/images/5", 0, 0, "2023-11-03 14:00:00", "2023-11-02 14:00:00", "post1111", "1"); + jdbcTemplate.update("insert into post (post_id, member_id, family_id, mission_id, type, post_img_url, comment_cnt, reaction_cnt, created_at, updated_at, content, post_img_key) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + "6", TEST_MEMBER2_ID, TEST_FAMILY_ID, 1, "SURVIVAL", "https://storage.com/images/6", 0, 0, "2023-11-03 15:00:00", "2023-11-02 15:00:00", "post2222", "2"); + + jdbcTemplate.update("insert into post (post_id, member_id, family_id, mission_id, type, post_img_url, comment_cnt, reaction_cnt, created_at, updated_at, content, post_img_key) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + "7", TEST_MEMBER1_ID, TEST_FAMILY_ID, 1, "MISSION", "https://storage.com/images/7", 0, 0, "2023-11-02 14:00:00", "2023-11-02 14:00:00", "post1111", "1"); + jdbcTemplate.update("insert into post (post_id, member_id, family_id, mission_id, type, post_img_url, comment_cnt, reaction_cnt, created_at, updated_at, content, post_img_key) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + "8", TEST_MEMBER2_ID, TEST_FAMILY_ID, 1, "MISSION", "https://storage.com/images/8", 0, 0, "2023-11-02 15:00:00", "2023-11-02 15:00:00", "post2222", "2"); + + // mission + String missionId = missionService.createMission(new CreateMissionRequest("오늘의 기분을 나타내는 사진 찍기.")).id(); + Mission mission = missionService.getMissionByMissionId(missionId); + dailyMissionHistoryService.createDailyMissionHistory(LocalDate.parse(yearMonthDay, DateTimeFormatter.ISO_DATE), mission); + + + // When + ResultActions result = mockMvc.perform(get("/v1/calendar") + .param("type", "DAILY") + .param("yearMonthDay", yearMonthDay) + .header("X-AUTH-TOKEN", TEST_MEMBER1_TOKEN) + ); + + // Then + result.andExpect(status().isOk()) + .andExpect(jsonPath("$.results[0].date").value("2023-11-02")) + .andExpect(jsonPath("$.results[0].type").value("SURVIVAL")) + .andExpect(jsonPath("$.results[0].postId").value("3")) + .andExpect(jsonPath("$.results[0].missionContent").isEmpty()) + .andExpect(jsonPath("$.results[0].allFamilyMembersUploaded").value(true)) + .andExpect(jsonPath("$.results[1].date").value("2023-11-02")) + .andExpect(jsonPath("$.results[1].type").value("SURVIVAL")) + .andExpect(jsonPath("$.results[1].postId").value("4")) + .andExpect(jsonPath("$.results[1].missionContent").isEmpty()) + .andExpect(jsonPath("$.results[1].allFamilyMembersUploaded").value(true)) + .andExpect(jsonPath("$.results[2].date").value("2023-11-02")) + .andExpect(jsonPath("$.results[2].type").value("MISSION")) + .andExpect(jsonPath("$.results[2].postId").value("7")) + .andExpect(jsonPath("$.results[2].missionContent").value("오늘의 기분을 나타내는 사진 찍기.")) + .andExpect(jsonPath("$.results[2].allFamilyMembersUploaded").value(true)) + .andExpect(jsonPath("$.results[3].date").value("2023-11-02")) + .andExpect(jsonPath("$.results[3].type").value("MISSION")) + .andExpect(jsonPath("$.results[3].postId").value("8")) + .andExpect(jsonPath("$.results[3].missionContent").value("오늘의 기분을 나타내는 사진 찍기.")) + .andExpect(jsonPath("$.results[3].allFamilyMembersUploaded").value(true)); + + } + + @Test + void 캘린더의_게시글_정책에_적합한_일간_캘린더_조회_테스트() throws Exception { + // Given + // parameterss + String yearMonthDay = "2023-11-02"; + + // posts + jdbcTemplate.update("insert into post (post_id, member_id, family_id, mission_id, type, post_img_url, comment_cnt, reaction_cnt, created_at, updated_at, content, post_img_key) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + "1", TEST_MEMBER1_ID, TEST_FAMILY_ID, 1, "SURVIVAL", "https://storage.com/images/3", 0, 0, "2023-11-02 14:01:00", "2023-11-02 14:01:00", "post1111", "1"); + + jdbcTemplate.update("insert into post (post_id, member_id, family_id, mission_id, type, post_img_url, comment_cnt, reaction_cnt, created_at, updated_at, content, post_img_key) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + "2", TEST_MEMBER1_ID, TEST_FAMILY_ID, 1, "MISSION", "https://storage.com/images/7", 0, 0, "2023-11-02 14:02:00", "2023-11-02 14:02:00", "post1111", "1"); + jdbcTemplate.update("insert into post (post_id, member_id, family_id, mission_id, type, post_img_url, comment_cnt, reaction_cnt, created_at, updated_at, content, post_img_key) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + "3", TEST_MEMBER2_ID, TEST_FAMILY_ID, 1, "MISSION", "https://storage.com/images/8", 0, 0, "2023-11-02 15:03:00", "2023-11-02 15:03:00", "post2222", "2"); + + jdbcTemplate.update("insert into post (post_id, member_id, family_id, mission_id, type, post_img_url, comment_cnt, reaction_cnt, created_at, updated_at, content, post_img_key) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + "4", TEST_MEMBER2_ID, TEST_FAMILY_ID, 1, "SURVIVAL", "https://storage.com/images/4", 0, 0, "2023-11-02 15:04:00", "2023-11-02 15:04:00", "post2222", "2"); + + // mission + String missionId = missionService.createMission(new CreateMissionRequest("오늘의 기분을 나타내는 사진 찍기.")).id(); + Mission mission = missionService.getMissionByMissionId(missionId); + dailyMissionHistoryService.createDailyMissionHistory(LocalDate.parse(yearMonthDay, DateTimeFormatter.ISO_DATE), mission); + + + // When + ResultActions result = mockMvc.perform(get("/v1/calendar") + .param("type", "DAILY") + .param("yearMonthDay", yearMonthDay) + .header("X-AUTH-TOKEN", TEST_MEMBER1_TOKEN) + ); + + // Then + result.andExpect(status().isOk()) + .andExpect(jsonPath("$.results[0].date").value("2023-11-02")) + .andExpect(jsonPath("$.results[0].type").value("SURVIVAL")) + .andExpect(jsonPath("$.results[0].postId").value("1")) + .andExpect(jsonPath("$.results[0].missionContent").isEmpty()) + .andExpect(jsonPath("$.results[0].allFamilyMembersUploaded").value(true)) + .andExpect(jsonPath("$.results[1].date").value("2023-11-02")) + .andExpect(jsonPath("$.results[1].type").value("SURVIVAL")) + .andExpect(jsonPath("$.results[1].postId").value("4")) + .andExpect(jsonPath("$.results[1].missionContent").isEmpty()) + .andExpect(jsonPath("$.results[1].allFamilyMembersUploaded").value(true)) + .andExpect(jsonPath("$.results[2].date").value("2023-11-02")) + .andExpect(jsonPath("$.results[2].type").value("MISSION")) + .andExpect(jsonPath("$.results[2].postId").value("2")) + .andExpect(jsonPath("$.results[2].missionContent").value("오늘의 기분을 나타내는 사진 찍기.")) + .andExpect(jsonPath("$.results[2].allFamilyMembersUploaded").value(true)) + .andExpect(jsonPath("$.results[3].date").value("2023-11-02")) + .andExpect(jsonPath("$.results[3].type").value("MISSION")) + .andExpect(jsonPath("$.results[3].postId").value("3")) + .andExpect(jsonPath("$.results[3].missionContent").value("오늘의 기분을 나타내는 사진 찍기.")) + .andExpect(jsonPath("$.results[3].allFamilyMembersUploaded").value(true)); + + } + + @Test + void 일간_캘린더_조회시_가족구성원_전체_업로드_여부_테스트() throws Exception { + // Given + // parameterss + String yearMonthDay = "2023-11-02"; + + // posts + jdbcTemplate.update("insert into post (post_id, member_id, family_id, mission_id, type, post_img_url, comment_cnt, reaction_cnt, created_at, updated_at, content, post_img_key) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + "1", TEST_MEMBER1_ID, TEST_FAMILY_ID, 1, "SURVIVAL", "https://storage.com/images/3", 0, 0, "2023-11-02 14:01:00", "2023-11-02 14:01:00", "post1111", "1"); + + // mission + String missionId = missionService.createMission(new CreateMissionRequest("오늘의 기분을 나타내는 사진 찍기.")).id(); + Mission mission = missionService.getMissionByMissionId(missionId); + dailyMissionHistoryService.createDailyMissionHistory(LocalDate.parse(yearMonthDay, DateTimeFormatter.ISO_DATE), mission); + + + // When + ResultActions result = mockMvc.perform(get("/v1/calendar") + .param("type", "DAILY") + .param("yearMonthDay", yearMonthDay) + .header("X-AUTH-TOKEN", TEST_MEMBER1_TOKEN) + ); + + // Then + result.andExpect(status().isOk()) + .andExpect(jsonPath("$.results[0].date").value("2023-11-02")) + .andExpect(jsonPath("$.results[0].type").value("SURVIVAL")) + .andExpect(jsonPath("$.results[0].postId").value("1")) + .andExpect(jsonPath("$.results[0].missionContent").isEmpty()) + .andExpect(jsonPath("$.results[0].allFamilyMembersUploaded").value(false)); + + } + + @Test - void 월별_캘린더_조회_테스트() throws Exception { + void 월간_캘린더_조회_테스트() throws Exception { // Given // parameterss String yearMonth = "2023-11"; @@ -164,7 +329,7 @@ void setUp() throws Exception { @Test - void 월별_캘린더_뒤늦게_가족에_가입한_멤버를_고려한_조회_테스트() throws Exception { + void 월간_캘린더_뒤늦게_가족에_가입한_멤버를_고려한_조회_테스트() throws Exception { // parameters String yearMonth = "2023-11"; @@ -203,7 +368,7 @@ void setUp() throws Exception { } @Test - void 월별_캘린더_가족을_탈퇴한_멤버를_고려한_조회_테스트() throws Exception { + void 월간_캘린더_가족을_탈퇴한_멤버를_고려한_조회_테스트() throws Exception { // Given // parameters String yearMonth = "2023-11"; diff --git a/mission/src/main/java/com/oing/service/MissionService.java b/mission/src/main/java/com/oing/service/MissionService.java index f9b55785..3d601a1b 100644 --- a/mission/src/main/java/com/oing/service/MissionService.java +++ b/mission/src/main/java/com/oing/service/MissionService.java @@ -46,9 +46,12 @@ public Mission getMissionByMissionId(String missionId) { } public MissionResponse getMissionByDate(LocalDate date) { - Mission mission = dailyMissionHistoryService.getDailyMissionHistoryByDate(date).getMission(); + return new MissionResponse("1", "오늘의 기분을 나타내는 사진 찍기."); - return MissionResponse.from(mission); + // TODO: Mocking 제거 시, 주석 해제 +// Mission mission = dailyMissionHistoryService.getDailyMissionHistoryByDate(date).getMission(); +// +// return MissionResponse.from(mission); } From 138a3e139122a9ea7073cfb5c82c9f061823858a Mon Sep 17 00:00:00 2001 From: Kwon770 Date: Sat, 27 Apr 2024 02:51:25 +0900 Subject: [PATCH 3/6] refactor: Remove debug system print code --- .../src/main/java/com/oing/controller/CalendarController.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/gateway/src/main/java/com/oing/controller/CalendarController.java b/gateway/src/main/java/com/oing/controller/CalendarController.java index 3ab7bd44..35d32cf3 100644 --- a/gateway/src/main/java/com/oing/controller/CalendarController.java +++ b/gateway/src/main/java/com/oing/controller/CalendarController.java @@ -43,11 +43,8 @@ public ArrayResponse getDailyCalendar(String yearMonthDay String missionContent = missionBridge.getContentByDate(date); HashSet uploadedFamilyMembers = survivalPosts.stream().map(PostResponse::authorId).collect(Collectors.toCollection(HashSet::new)); - System.out.println(uploadedFamilyMembers.toString()); List familyMembersIds = memberBridge.getFamilyMembersIdsByFamilyId(loginFamilyId); - System.out.println(familyMembersIds.toString()); boolean allFamilyMembersUploaded = uploadedFamilyMembers.containsAll(familyMembersIds); - System.out.println(allFamilyMembersUploaded); survivalPosts.forEach(post -> dailyCalendarResponses.add(new DailyCalendarResponse(date, PostType.SURVIVAL, post.postId(), post.imageUrl(), null, allFamilyMembersUploaded))); missionPosts.forEach(post -> dailyCalendarResponses.add(new DailyCalendarResponse(date, PostType.MISSION, post.postId(), post.imageUrl(), missionContent, allFamilyMembersUploaded))); From d100098f79f3975f34f7c5d598d2776cfcd20300 Mon Sep 17 00:00:00 2001 From: Kwon770 Date: Sun, 28 Apr 2024 17:48:01 +0900 Subject: [PATCH 4/6] refactor: Extract the code to map post to calendar response as the method --- .../oing/controller/CalendarController.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/gateway/src/main/java/com/oing/controller/CalendarController.java b/gateway/src/main/java/com/oing/controller/CalendarController.java index 35d32cf3..af98a761 100644 --- a/gateway/src/main/java/com/oing/controller/CalendarController.java +++ b/gateway/src/main/java/com/oing/controller/CalendarController.java @@ -18,6 +18,9 @@ import java.util.List; import java.util.stream.Collectors; +import static com.oing.domain.PostType.MISSION; +import static com.oing.domain.PostType.SURVIVAL; + @Controller @RequiredArgsConstructor public class CalendarController implements CalendarApi { @@ -38,19 +41,26 @@ public ArrayResponse getDailyCalendar(String yearMonthDay List dailyCalendarResponses = new ArrayList<>(); LocalDate date = LocalDate.parse(yearMonthDay, DateTimeFormatter.ISO_DATE); - Collection survivalPosts = postController.fetchDailyFeeds(1, 10, date, null, "ASC", PostType.SURVIVAL, loginMemberId, true).results(); - Collection missionPosts = postController.fetchDailyFeeds(1, 10, date, null, "ASC", PostType.MISSION, loginMemberId, true).results(); + Collection survivalPosts = postController.fetchDailyFeeds(1, 10, date, null, "ASC", SURVIVAL, loginMemberId, true).results(); + Collection missionPosts = postController.fetchDailyFeeds(1, 10, date, null, "ASC", MISSION, loginMemberId, true).results(); String missionContent = missionBridge.getContentByDate(date); HashSet uploadedFamilyMembers = survivalPosts.stream().map(PostResponse::authorId).collect(Collectors.toCollection(HashSet::new)); List familyMembersIds = memberBridge.getFamilyMembersIdsByFamilyId(loginFamilyId); boolean allFamilyMembersUploaded = uploadedFamilyMembers.containsAll(familyMembersIds); - survivalPosts.forEach(post -> dailyCalendarResponses.add(new DailyCalendarResponse(date, PostType.SURVIVAL, post.postId(), post.imageUrl(), null, allFamilyMembersUploaded))); - missionPosts.forEach(post -> dailyCalendarResponses.add(new DailyCalendarResponse(date, PostType.MISSION, post.postId(), post.imageUrl(), missionContent, allFamilyMembersUploaded))); + dailyCalendarResponses.addAll(convertToDailyCalendarResponse(survivalPosts, missionContent, allFamilyMembersUploaded)); + dailyCalendarResponses.addAll(convertToDailyCalendarResponse(missionPosts, missionContent, allFamilyMembersUploaded)); return ArrayResponse.of(dailyCalendarResponses); } + private List convertToDailyCalendarResponse(Collection postResponses, String missionContent, boolean allFamilyMembersUploaded) { + return postResponses.stream().map(postResponse -> switch (PostType.valueOf(postResponse.type())) { + case MISSION -> new DailyCalendarResponse(postResponse.createdAt().toLocalDate(), MISSION, postResponse.postId(), postResponse.imageUrl(), missionContent, allFamilyMembersUploaded); + case SURVIVAL -> new DailyCalendarResponse(postResponse.createdAt().toLocalDate(), SURVIVAL, postResponse.postId(), postResponse.imageUrl(), null, allFamilyMembersUploaded); + }).toList(); + } + @Override public ArrayResponse getMonthlyCalendar(String yearMonth, String familyId) { @@ -60,11 +70,11 @@ public ArrayResponse getMonthlyCalendar(String yearMont LocalDate endDate = startDate.plusMonths(1); List daysLatestPosts = postService.findLatestPostOfEveryday(startDate, endDate, familyId); - List monthlyCalendarRespons = convertToCalendarResponse(daysLatestPosts, familyId); + List monthlyCalendarRespons = convertToMonthlyCalendarResponse(daysLatestPosts, familyId); return new ArrayResponse<>(monthlyCalendarRespons); } - private List convertToCalendarResponse(List daysLatestPosts, String familyId) { + private List convertToMonthlyCalendarResponse(List daysLatestPosts, String familyId) { List monthlyCalendarRespons = new ArrayList<>(); for (Post dayLatestPost : daysLatestPosts) { @@ -75,7 +85,7 @@ private List convertToCalendarResponse(List daysL List familyMembersIds = memberService.getFamilyMembersIdsByFamilyIdAndJoinAtBefore(familyId, postDate.plusDays(1)); boolean allFamilyMembersUploaded = true; for (String memberId : familyMembersIds) { - if (!postService.existsByMemberIdAndFamilyIdAndTypeAndCreatedAt(memberId, familyId, PostType.SURVIVAL, postDate)) { + if (!postService.existsByMemberIdAndFamilyIdAndTypeAndCreatedAt(memberId, familyId, SURVIVAL, postDate)) { allFamilyMembersUploaded = false; break; } @@ -119,7 +129,7 @@ public BannerResponse getBanner(String yearMonth, String familyId) { if (postService.existsByFamilyIdAndCreatedAt(familyId, startDate)) { List familyMembersIds = memberService.getFamilyMembersIdsByFamilyIdAndJoinAtBefore(familyId, startDate.plusDays(1)); for (String memberId : familyMembersIds) { - if (!postService.existsByMemberIdAndFamilyIdAndTypeAndCreatedAt(memberId, familyId, PostType.SURVIVAL, startDate)) { + if (!postService.existsByMemberIdAndFamilyIdAndTypeAndCreatedAt(memberId, familyId, SURVIVAL, startDate)) { allFamilyMembersUploaded = false; break; } From 8a667def5e092a9ed500abc1f397b565a232327f Mon Sep 17 00:00:00 2001 From: Kwon770 Date: Sun, 28 Apr 2024 17:54:05 +0900 Subject: [PATCH 5/6] refactor: Extract the code to calculate allFamilyMembersUploaded as the method --- .../oing/controller/CalendarController.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/gateway/src/main/java/com/oing/controller/CalendarController.java b/gateway/src/main/java/com/oing/controller/CalendarController.java index af98a761..43106bb4 100644 --- a/gateway/src/main/java/com/oing/controller/CalendarController.java +++ b/gateway/src/main/java/com/oing/controller/CalendarController.java @@ -44,20 +44,24 @@ public ArrayResponse getDailyCalendar(String yearMonthDay Collection survivalPosts = postController.fetchDailyFeeds(1, 10, date, null, "ASC", SURVIVAL, loginMemberId, true).results(); Collection missionPosts = postController.fetchDailyFeeds(1, 10, date, null, "ASC", MISSION, loginMemberId, true).results(); String missionContent = missionBridge.getContentByDate(date); - - HashSet uploadedFamilyMembers = survivalPosts.stream().map(PostResponse::authorId).collect(Collectors.toCollection(HashSet::new)); - List familyMembersIds = memberBridge.getFamilyMembersIdsByFamilyId(loginFamilyId); - boolean allFamilyMembersUploaded = uploadedFamilyMembers.containsAll(familyMembersIds); + boolean allFamilyMembersUploaded = getAllFamilyMembersUploaded(survivalPosts, loginFamilyId); dailyCalendarResponses.addAll(convertToDailyCalendarResponse(survivalPosts, missionContent, allFamilyMembersUploaded)); dailyCalendarResponses.addAll(convertToDailyCalendarResponse(missionPosts, missionContent, allFamilyMembersUploaded)); return ArrayResponse.of(dailyCalendarResponses); } - private List convertToDailyCalendarResponse(Collection postResponses, String missionContent, boolean allFamilyMembersUploaded) { - return postResponses.stream().map(postResponse -> switch (PostType.valueOf(postResponse.type())) { - case MISSION -> new DailyCalendarResponse(postResponse.createdAt().toLocalDate(), MISSION, postResponse.postId(), postResponse.imageUrl(), missionContent, allFamilyMembersUploaded); - case SURVIVAL -> new DailyCalendarResponse(postResponse.createdAt().toLocalDate(), SURVIVAL, postResponse.postId(), postResponse.imageUrl(), null, allFamilyMembersUploaded); + private boolean getAllFamilyMembersUploaded(Collection survivalPosts, String familyId) { + HashSet uploadedFamilyMembers = survivalPosts.stream().map(PostResponse::authorId).collect(Collectors.toCollection(HashSet::new)); + List familyMembersIds = memberService.getFamilyMembersIdsByFamilyIdAndJoinAtBefore(familyId, LocalDate.now()); + + return uploadedFamilyMembers.containsAll(familyMembersIds); + } + + private List convertToDailyCalendarResponse(Collection posts, String missionContent, boolean allFamilyMembersUploaded) { + return posts.stream().map(post -> switch (PostType.valueOf(post.type())) { + case MISSION -> new DailyCalendarResponse(post.createdAt().toLocalDate(), MISSION, post.postId(), post.imageUrl(), missionContent, allFamilyMembersUploaded); + case SURVIVAL -> new DailyCalendarResponse(post.createdAt().toLocalDate(), SURVIVAL, post.postId(), post.imageUrl(), null, allFamilyMembersUploaded); }).toList(); } From c6c64e08e993c3789675d2115f7e1fe94a7858ac Mon Sep 17 00:00:00 2001 From: Kwon770 Date: Sun, 28 Apr 2024 18:00:07 +0900 Subject: [PATCH 6/6] fix: Fix the runtime exception during PostType enum mapping --- .../src/main/java/com/oing/controller/CalendarController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway/src/main/java/com/oing/controller/CalendarController.java b/gateway/src/main/java/com/oing/controller/CalendarController.java index 43106bb4..8242ddf2 100644 --- a/gateway/src/main/java/com/oing/controller/CalendarController.java +++ b/gateway/src/main/java/com/oing/controller/CalendarController.java @@ -59,7 +59,7 @@ private boolean getAllFamilyMembersUploaded(Collection survivalPos } private List convertToDailyCalendarResponse(Collection posts, String missionContent, boolean allFamilyMembersUploaded) { - return posts.stream().map(post -> switch (PostType.valueOf(post.type())) { + return posts.stream().map(post -> switch (PostType.fromString(post.type())) { case MISSION -> new DailyCalendarResponse(post.createdAt().toLocalDate(), MISSION, post.postId(), post.imageUrl(), missionContent, allFamilyMembersUploaded); case SURVIVAL -> new DailyCalendarResponse(post.createdAt().toLocalDate(), SURVIVAL, post.postId(), post.imageUrl(), null, allFamilyMembersUploaded); }).toList();