From 1973f92a8a904c7f2fe39a9bf7e83f1473ce9de7 Mon Sep 17 00:00:00 2001 From: Kwon770 Date: Sat, 11 May 2024 20:30:42 +0900 Subject: [PATCH] feat: Change the policy of monthly calendar thumbnail as the oldest survival post --- .../com/oing/controller/CalendarController.java | 2 +- .../java/com/oing/controller/WidgetController.java | 2 +- .../oing/repository/PostRepositoryCustomImpl.java | 14 +++++++++----- .../oing/controller/CalendarControllerTest.java | 2 +- .../com/oing/controller/WidgetControllerTest.java | 6 +++--- .../oing/repository/PostRepositoryCustomTest.java | 3 +-- .../com/oing/repository/PostRepositoryCustom.java | 2 +- .../main/java/com/oing/service/PostService.java | 4 ++-- 8 files changed, 19 insertions(+), 16 deletions(-) diff --git a/gateway/src/main/java/com/oing/controller/CalendarController.java b/gateway/src/main/java/com/oing/controller/CalendarController.java index 651e80c9..e544da3f 100644 --- a/gateway/src/main/java/com/oing/controller/CalendarController.java +++ b/gateway/src/main/java/com/oing/controller/CalendarController.java @@ -73,7 +73,7 @@ public ArrayResponse getMonthlyCalendar(String yearMont LocalDate startDate = LocalDate.parse(yearMonth + "-01"); // yyyy-MM-dd 패턴으로 파싱 LocalDate endDate = startDate.plusMonths(1); - List daysLatestPosts = postService.findLatestPostOfEveryday(startDate, endDate, familyId); + List daysLatestPosts = postService.findOldestPostOfEveryday(startDate, endDate, familyId); List monthlyCalendarResponses = convertToMonthlyCalendarResponse(daysLatestPosts, familyId); return new ArrayResponse<>(monthlyCalendarResponses); } diff --git a/gateway/src/main/java/com/oing/controller/WidgetController.java b/gateway/src/main/java/com/oing/controller/WidgetController.java index b3145a91..9b5ee0dd 100644 --- a/gateway/src/main/java/com/oing/controller/WidgetController.java +++ b/gateway/src/main/java/com/oing/controller/WidgetController.java @@ -32,7 +32,7 @@ public ResponseEntity getSingleRecentFamilyPostW LocalDate endDate = startDate.plusDays(1); - List latestPosts = postService.findLatestPostOfEveryday(startDate, endDate, loginFamilyId); + List latestPosts = postService.findOldestPostOfEveryday(startDate, endDate, loginFamilyId); if (latestPosts.isEmpty()) { return ResponseEntity.noContent().build(); } diff --git a/gateway/src/main/java/com/oing/repository/PostRepositoryCustomImpl.java b/gateway/src/main/java/com/oing/repository/PostRepositoryCustomImpl.java index 9b2a5ba4..180a3f85 100644 --- a/gateway/src/main/java/com/oing/repository/PostRepositoryCustomImpl.java +++ b/gateway/src/main/java/com/oing/repository/PostRepositoryCustomImpl.java @@ -20,6 +20,7 @@ import java.time.ZonedDateTime; import java.util.List; +import static com.oing.domain.PostType.*; import static com.oing.domain.QMember.member; import static com.oing.domain.QPost.post; @@ -38,15 +39,18 @@ public List getMemberIdsPostedToday(LocalDate date) { } @Override - public List findLatestPostOfEveryday(LocalDateTime startDate, LocalDateTime endDate, String familyId) { + public List findOldestPostOfEveryday(LocalDateTime startDate, LocalDateTime endDate, String familyId) { return queryFactory .selectFrom(post) .where(post.id.in( JPAExpressions - .select(post.id.max()) + .select(post.id.min()) .from(post) - .where(post.familyId.eq(familyId) - .and(post.createdAt.between(startDate, endDate))) + .where( + post.familyId.eq(familyId), + post.type.eq(SURVIVAL), + post.createdAt.between(startDate, endDate) + ) .groupBy(Expressions.dateOperation(LocalDate.class, Ops.DateTimeOps.DATE, post.createdAt)) )) .orderBy(post.createdAt.asc()) @@ -150,7 +154,7 @@ public int countTodaySurvivalPostsByFamilyId(String familyId) { .select(post.id.count()) .from(post) .where(post.familyId.eq(familyId), - post.type.eq(PostType.SURVIVAL), + post.type.eq(SURVIVAL), dateExpr(post.createdAt).eq(today)) .fetchFirst(); return count.intValue(); diff --git a/gateway/src/test/java/com/oing/controller/CalendarControllerTest.java b/gateway/src/test/java/com/oing/controller/CalendarControllerTest.java index 472ffea8..4ffc626d 100644 --- a/gateway/src/test/java/com/oing/controller/CalendarControllerTest.java +++ b/gateway/src/test/java/com/oing/controller/CalendarControllerTest.java @@ -108,7 +108,7 @@ class CalendarControllerTest { ); ReflectionTestUtils.setField(testPost4, "createdAt", LocalDateTime.of(2023, 11, 9, 13, 0)); List representativePosts = List.of(testPost1, testPost2, testPost3, testPost4); - when(postService.findLatestPostOfEveryday(startDate, endDate, familyId)).thenReturn(representativePosts); + when(postService.findOldestPostOfEveryday(startDate, endDate, familyId)).thenReturn(representativePosts); // When ArrayResponse weeklyCalendar = calendarController.getMonthlyCalendar(yearMonth, familyId); diff --git a/gateway/src/test/java/com/oing/controller/WidgetControllerTest.java b/gateway/src/test/java/com/oing/controller/WidgetControllerTest.java index a1da7b25..ab301de2 100644 --- a/gateway/src/test/java/com/oing/controller/WidgetControllerTest.java +++ b/gateway/src/test/java/com/oing/controller/WidgetControllerTest.java @@ -75,7 +75,7 @@ class WidgetControllerTest { String date = "2024-10-18"; String familyId = testMember1.getFamilyId(); - when(postService.findLatestPostOfEveryday(LocalDate.parse(date), LocalDate.parse(date).plusDays(1), familyId)).thenReturn(List.of(testPost1)); + when(postService.findOldestPostOfEveryday(LocalDate.parse(date), LocalDate.parse(date).plusDays(1), familyId)).thenReturn(List.of(testPost1)); when(memberService.getMemberByMemberId(testPost1.getMemberId())).thenReturn(testMember1); when(optimizedImageUrlGenerator.getKBImageUrlGenerator(testMember1.getProfileImgUrl())).thenReturn(testMember1.getProfileImgUrl()); when(optimizedImageUrlGenerator.getKBImageUrlGenerator(testPost1.getPostImgUrl())).thenReturn(testPost1.getPostImgUrl()); @@ -106,7 +106,7 @@ class WidgetControllerTest { String date = null; String familyId = testMember1.getFamilyId(); - when(postService.findLatestPostOfEveryday(LocalDate.now(), LocalDate.now().plusDays(1), familyId)).thenReturn(List.of(testPost1)); + when(postService.findOldestPostOfEveryday(LocalDate.now(), LocalDate.now().plusDays(1), familyId)).thenReturn(List.of(testPost1)); when(memberService.getMemberByMemberId(testPost1.getMemberId())).thenReturn(testMember1); when(optimizedImageUrlGenerator.getKBImageUrlGenerator(testMember1.getProfileImgUrl())).thenReturn(testMember1.getProfileImgUrl()); when(optimizedImageUrlGenerator.getKBImageUrlGenerator(testPost1.getPostImgUrl())).thenReturn(testPost1.getPostImgUrl()); @@ -137,7 +137,7 @@ class WidgetControllerTest { String date = "2024-10-18"; String familyId = testMember1.getFamilyId(); - when(postService.findLatestPostOfEveryday(LocalDate.parse(date), LocalDate.parse(date).plusDays(1), familyId)).thenReturn(List.of()); + when(postService.findOldestPostOfEveryday(LocalDate.parse(date), LocalDate.parse(date).plusDays(1), familyId)).thenReturn(List.of()); // when ResponseEntity response = widgetController.getSingleRecentFamilyPostWidget(date, familyId); diff --git a/gateway/src/test/java/com/oing/repository/PostRepositoryCustomTest.java b/gateway/src/test/java/com/oing/repository/PostRepositoryCustomTest.java index 30802c72..9a348c2e 100644 --- a/gateway/src/test/java/com/oing/repository/PostRepositoryCustomTest.java +++ b/gateway/src/test/java/com/oing/repository/PostRepositoryCustomTest.java @@ -4,7 +4,6 @@ import com.oing.domain.Family; import com.oing.domain.Member; import com.oing.domain.Post; -import com.oing.domain.PostType; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -106,7 +105,7 @@ void setup() { void 각_날짜에서_가장_마지막으로_업로드된_게시글을_조회한다() { // When String familyId = testMember1.getFamilyId(); - List posts = postRepositoryCustomImpl.findLatestPostOfEveryday(LocalDateTime.of(2023, 11, 1, 0, 0, 0), LocalDateTime.of(2023, 12, 1, 0, 0, 0), familyId); + List posts = postRepositoryCustomImpl.findOldestPostOfEveryday(LocalDateTime.of(2023, 11, 1, 0, 0, 0), LocalDateTime.of(2023, 12, 1, 0, 0, 0), familyId); // Then assertThat(posts) diff --git a/post/src/main/java/com/oing/repository/PostRepositoryCustom.java b/post/src/main/java/com/oing/repository/PostRepositoryCustom.java index 8a912308..9fadd438 100644 --- a/post/src/main/java/com/oing/repository/PostRepositoryCustom.java +++ b/post/src/main/java/com/oing/repository/PostRepositoryCustom.java @@ -11,7 +11,7 @@ public interface PostRepositoryCustom { List getMemberIdsPostedToday(LocalDate date); - List findLatestPostOfEveryday(LocalDateTime startDate, LocalDateTime endDate, String familyId); + List findOldestPostOfEveryday(LocalDateTime startDate, LocalDateTime endDate, String familyId); Post findLatestPost(LocalDateTime startDate, LocalDateTime endDate, PostType postType, String familyId); diff --git a/post/src/main/java/com/oing/service/PostService.java b/post/src/main/java/com/oing/service/PostService.java index a03d518c..79fb3f32 100644 --- a/post/src/main/java/com/oing/service/PostService.java +++ b/post/src/main/java/com/oing/service/PostService.java @@ -108,8 +108,8 @@ private void validateUploadTime(String memberId, ZonedDateTime uploadTime) { } } - public List findLatestPostOfEveryday(LocalDate inclusiveStartDate, LocalDate exclusiveEndDate, String familyId) { - return postRepository.findLatestPostOfEveryday(inclusiveStartDate.atStartOfDay(), exclusiveEndDate.atStartOfDay(), familyId); + public List findOldestPostOfEveryday(LocalDate inclusiveStartDate, LocalDate exclusiveEndDate, String familyId) { + return postRepository.findOldestPostOfEveryday(inclusiveStartDate.atStartOfDay(), exclusiveEndDate.atStartOfDay(), familyId); } public Post getMemberPostById(String postId) {