Skip to content

Commit

Permalink
feat: Change the policy of monthly calendar thumbnail as the oldest s…
Browse files Browse the repository at this point in the history
…urvival post
  • Loading branch information
Kwon770 committed May 11, 2024
1 parent 27f7f27 commit 1973f92
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public ArrayResponse<MonthlyCalendarResponse> getMonthlyCalendar(String yearMont
LocalDate startDate = LocalDate.parse(yearMonth + "-01"); // yyyy-MM-dd 패턴으로 파싱
LocalDate endDate = startDate.plusMonths(1);

List<Post> daysLatestPosts = postService.findLatestPostOfEveryday(startDate, endDate, familyId);
List<Post> daysLatestPosts = postService.findOldestPostOfEveryday(startDate, endDate, familyId);
List<MonthlyCalendarResponse> monthlyCalendarResponses = convertToMonthlyCalendarResponse(daysLatestPosts, familyId);
return new ArrayResponse<>(monthlyCalendarResponses);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ResponseEntity<SingleRecentPostWidgetResponse> getSingleRecentFamilyPostW
LocalDate endDate = startDate.plusDays(1);


List<Post> latestPosts = postService.findLatestPostOfEveryday(startDate, endDate, loginFamilyId);
List<Post> latestPosts = postService.findOldestPostOfEveryday(startDate, endDate, loginFamilyId);
if (latestPosts.isEmpty()) {
return ResponseEntity.noContent().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -38,15 +39,18 @@ public List<String> getMemberIdsPostedToday(LocalDate date) {
}

@Override
public List<Post> findLatestPostOfEveryday(LocalDateTime startDate, LocalDateTime endDate, String familyId) {
public List<Post> 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())
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class CalendarControllerTest {
);
ReflectionTestUtils.setField(testPost4, "createdAt", LocalDateTime.of(2023, 11, 9, 13, 0));
List<Post> 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<MonthlyCalendarResponse> weeklyCalendar = calendarController.getMonthlyCalendar(yearMonth, familyId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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<SingleRecentPostWidgetResponse> response = widgetController.getSingleRecentFamilyPostWidget(date, familyId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -106,7 +105,7 @@ void setup() {
void 각_날짜에서_가장_마지막으로_업로드된_게시글을_조회한다() {
// When
String familyId = testMember1.getFamilyId();
List<Post> posts = postRepositoryCustomImpl.findLatestPostOfEveryday(LocalDateTime.of(2023, 11, 1, 0, 0, 0), LocalDateTime.of(2023, 12, 1, 0, 0, 0), familyId);
List<Post> posts = postRepositoryCustomImpl.findOldestPostOfEveryday(LocalDateTime.of(2023, 11, 1, 0, 0, 0), LocalDateTime.of(2023, 12, 1, 0, 0, 0), familyId);

// Then
assertThat(posts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public interface PostRepositoryCustom {
List<String> getMemberIdsPostedToday(LocalDate date);

List<Post> findLatestPostOfEveryday(LocalDateTime startDate, LocalDateTime endDate, String familyId);
List<Post> findOldestPostOfEveryday(LocalDateTime startDate, LocalDateTime endDate, String familyId);

Post findLatestPost(LocalDateTime startDate, LocalDateTime endDate, PostType postType, String familyId);

Expand Down
4 changes: 2 additions & 2 deletions post/src/main/java/com/oing/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ private void validateUploadTime(String memberId, ZonedDateTime uploadTime) {
}
}

public List<Post> findLatestPostOfEveryday(LocalDate inclusiveStartDate, LocalDate exclusiveEndDate, String familyId) {
return postRepository.findLatestPostOfEveryday(inclusiveStartDate.atStartOfDay(), exclusiveEndDate.atStartOfDay(), familyId);
public List<Post> findOldestPostOfEveryday(LocalDate inclusiveStartDate, LocalDate exclusiveEndDate, String familyId) {
return postRepository.findOldestPostOfEveryday(inclusiveStartDate.atStartOfDay(), exclusiveEndDate.atStartOfDay(), familyId);
}

public Post getMemberPostById(String postId) {
Expand Down

0 comments on commit 1973f92

Please sign in to comment.