Skip to content

Commit 26e76e4

Browse files
authored
Fix/#57 기타 수정 (#58)
* fix: hasNext동작 방식 수정 * fix: FollowingPostDto 응답 수정 * fix: PostRepositoryTest 코드 수정
1 parent 9784d43 commit 26e76e4

File tree

4 files changed

+42
-16
lines changed

4 files changed

+42
-16
lines changed

src/main/java/org/ahpuh/surf/post/dto/FollowingPostDto.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public class FollowingPostDto {
1414

1515
private Long userId;
1616

17+
private String userName;
18+
19+
private String profilePhotoUrl;
20+
1721
private String categoryName;
1822

1923
private String colorCode;
@@ -30,7 +34,7 @@ public class FollowingPostDto {
3034

3135
private LocalDate selectedDate;
3236

33-
private LocalDateTime updatedAt;
37+
private LocalDateTime createdAt;
3438

3539
@Builder.Default
3640
private Long likeId = null;
@@ -40,6 +44,8 @@ public class FollowingPostDto {
4044

4145
@QueryProjection
4246
public FollowingPostDto(final Long userId,
47+
final String userName,
48+
final String profilePhotoUrl,
4349
final String categoryName,
4450
final String colorCode,
4551
final Long postId,
@@ -48,8 +54,10 @@ public FollowingPostDto(final Long userId,
4854
final String imageUrl,
4955
final String fileUrl,
5056
final LocalDate selectedDate,
51-
final LocalDateTime updatedAt) {
57+
final LocalDateTime createdAt) {
5258
this.userId = userId;
59+
this.userName = userName;
60+
this.profilePhotoUrl = profilePhotoUrl;
5361
this.categoryName = categoryName;
5462
this.colorCode = colorCode;
5563
this.postId = postId;
@@ -58,7 +66,7 @@ public FollowingPostDto(final Long userId,
5866
this.imageUrl = imageUrl;
5967
this.fileUrl = fileUrl;
6068
this.selectedDate = selectedDate;
61-
this.updatedAt = updatedAt;
69+
this.createdAt = createdAt;
6270
this.likeId = null;
6371
this.isLiked = false;
6472
}

src/main/java/org/ahpuh/surf/post/repository/PostRepositoryImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public List<FollowingPostDto> findFollowingPosts(final Long userId, final Pageab
2323
return queryFactory
2424
.select(new QFollowingPostDto(
2525
post.user.userId.as("userId"),
26+
post.user.userName.as("userName"),
27+
post.user.profilePhotoUrl.as("profilePhotoUrl"),
2628
post.category.name.as("categoryName"),
2729
post.category.colorCode.as("colorCode"),
2830
post.postId.as("postId"),
@@ -47,6 +49,8 @@ public List<FollowingPostDto> findNextFollowingPosts(final Long userId, final Lo
4749
return queryFactory
4850
.select(new QFollowingPostDto(
4951
post.user.userId.as("userId"),
52+
post.user.userName.as("userName"),
53+
post.user.profilePhotoUrl.as("profilePhotoUrl"),
5054
post.category.name.as("categoryName"),
5155
post.category.colorCode.as("colorCode"),
5256
post.postId.as("postId"),

src/main/java/org/ahpuh/surf/post/service/PostServiceImpl.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,15 @@ public CursorResult<FollowingPostDto> explore(final Long myId, final Long cursor
8787
.ifPresent(like -> dto.setLiked(like.getLikeId()));
8888
}
8989

90-
final Long lastIdOfIndex = followingPostDtos.isEmpty() ?
91-
null : followingPostDtos.get(followingPostDtos.size() - 1).getPostId();
90+
final long lastIdOfIndex = followingPostDtos.isEmpty() ? 0 : followingPostDtos.get(followingPostDtos.size() - 1).getPostId();
9291

93-
return new CursorResult<>(followingPostDtos, hasNext(lastIdOfIndex));
92+
final Boolean hasNext = postRepository.findNextFollowingPosts(
93+
myId,
94+
followingPostDtos.get(Math.toIntExact(lastIdOfIndex)).getSelectedDate(),
95+
followingPostDtos.get(Math.toIntExact(lastIdOfIndex)).getCreatedAt(),
96+
page).isEmpty();
97+
98+
return new CursorResult<>(followingPostDtos, hasNext);
9499
}
95100

96101
public List<PostCountDto> getCountsPerDayWithYear(final int year, final Long userId) {
@@ -134,13 +139,19 @@ public CursorResult<AllPostResponseDto> getAllPost(final Long myId, final Long u
134139
postRepository.findAllByUserOrderBySelectedDateDesc(user, page) :
135140
postRepository.findByUserAndSelectedDateLessThanAndCreatedAtLessThanOrderBySelectedDateDesc(user, findPost.getSelectedDate(), findPost.getCreatedAt(), page);
136141

137-
final Long lastIdOfIndex = postList.isEmpty() ? 0 : postList.get(postList.size() - 1).getPostId();
142+
final long lastIdOfIndex = postList.isEmpty() ? 0 : postList.get(postList.size() - 1).getPostId();
138143

139144
final List<AllPostResponseDto> posts = postList.stream()
140145
.map(post -> postConverter.toAllPostResponseDto(post, likeRepository.findByUserIdAndPost(myId, post)))
141146
.toList();
142147

143-
return new CursorResult<>(posts, hasNext(lastIdOfIndex));
148+
final Boolean hasNext = postRepository.findByUserAndSelectedDateLessThanAndCreatedAtLessThanOrderBySelectedDateDesc(
149+
user,
150+
postList.get(Math.toIntExact(lastIdOfIndex)).getSelectedDate(),
151+
postList.get(Math.toIntExact(lastIdOfIndex)).getCreatedAt(),
152+
page).isEmpty();
153+
154+
return new CursorResult<>(posts, hasNext);
144155
}
145156

146157
@Override
@@ -156,13 +167,20 @@ public CursorResult<AllPostResponseDto> getAllPostByCategory(final Long myId, fi
156167
postRepository.findAllByUserAndCategoryOrderBySelectedDateDesc(user, category, page) :
157168
postRepository.findByUserAndCategoryAndSelectedDateLessThanAndCreatedAtLessThanOrderBySelectedDateDesc(user, category, findPost.getSelectedDate(), findPost.getCreatedAt(), page);
158169

159-
final Long lastIdOfIndex = postList.isEmpty() ? 0 : postList.get(postList.size() - 1).getPostId();
170+
final long lastIdOfIndex = postList.isEmpty() ? 0 : postList.get(postList.size() - 1).getPostId();
160171

161172
final List<AllPostResponseDto> posts = postList.stream()
162173
.map(post -> postConverter.toAllPostResponseDto(post, likeRepository.findByUserIdAndPost(myId, post)))
163174
.toList();
164175

165-
return new CursorResult<>(posts, hasNext(lastIdOfIndex));
176+
final Boolean hasNext = postRepository.findByUserAndCategoryAndSelectedDateLessThanAndCreatedAtLessThanOrderBySelectedDateDesc(
177+
user,
178+
category,
179+
postList.get(Math.toIntExact(lastIdOfIndex)).getSelectedDate(),
180+
postList.get(Math.toIntExact(lastIdOfIndex)).getCreatedAt(),
181+
page).isEmpty();
182+
183+
return new CursorResult<>(posts, hasNext);
166184
}
167185

168186
public int getRecentScore(final Long categoryId) {
@@ -182,10 +200,4 @@ private Post getPostById(final Long postId) {
182200
return postRepository.findById(postId)
183201
.orElseThrow(() -> EntityExceptionHandler.PostNotFound(postId));
184202
}
185-
186-
private Boolean hasNext(final Long id) {
187-
final Post post = postRepository.findById(id).orElse(null);
188-
return post != null && postRepository.existsBySelectedDateLessThanAndCreatedAtLessThan(post.getSelectedDate(), post.getCreatedAt());
189-
}
190-
191203
}

src/test/java/org/ahpuh/surf/post/repository/PostRepositoryTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ void testQueryDsl() {
144144
final List<FollowingPostDto> posts = query
145145
.select(new QFollowingPostDto(
146146
post.user.userId.as("userId"),
147+
post.user.userName.as("userName"),
148+
post.user.profilePhotoUrl.as("profilePhotoUrl"),
147149
post.category.name.as("categoryName"),
148150
post.category.colorCode.as("colorCode"),
149151
post.postId.as("postId"),

0 commit comments

Comments
 (0)