Skip to content

Commit 3f8af5b

Browse files
committed
hotfix: bug fix
1 parent 32e0fcd commit 3f8af5b

File tree

4 files changed

+58
-23
lines changed

4 files changed

+58
-23
lines changed

โ€Žsrc/main/java/org/ahpuh/surf/post/dto/PostRequestDto.javaโ€Ž

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import lombok.*;
44

5-
import javax.validation.constraints.NotBlank;
6-
import javax.validation.constraints.NotNull;
7-
import javax.validation.constraints.Size;
5+
import javax.validation.constraints.*;
86

97
@Getter
108
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@@ -22,7 +20,8 @@ public class PostRequestDto {
2220
@Size(max = 500, message = "Post contents length must within 500.")
2321
private String content;
2422

25-
@Size(max = 100, message = "Score must be 0 ~ 100.")
26-
private int score;
23+
@Min(0)
24+
@Max(100)
25+
private Integer score;
2726

2827
}

โ€Žsrc/main/java/org/ahpuh/surf/post/repository/PostRepositoryImpl.javaโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public List<FollowingPostDto> findFollowingPosts(final Long userId, final Pageab
3939
.leftJoin(follow).on(follow.user.userId.eq(userId))
4040
.where(follow.followedUser.userId.eq(post.user.userId), post.isDeleted.eq(false))
4141
.groupBy(post.postId, follow.followId)
42-
.orderBy(post.selectedDate.desc())
42+
.orderBy(post.selectedDate.desc(), post.createdAt.desc())
4343
.limit(page.getPageSize())
4444
.fetch();
4545
}

โ€Žsrc/main/java/org/ahpuh/surf/post/service/PostServiceImpl.javaโ€Ž

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,20 @@ public CursorResult<FollowingPostDto> explore(final Long myId, final Long cursor
8989

9090
final long lastIdOfIndex = followingPostDtos.isEmpty() ? 0 : followingPostDtos.get(followingPostDtos.size() - 1).getPostId();
9191

92-
final Boolean hasNext = postRepository.findNextFollowingPosts(
92+
final boolean hasNext = !postRepository.findNextFollowingPosts(
9393
myId,
94-
followingPostDtos.get(Math.toIntExact(lastIdOfIndex)).getSelectedDate(),
95-
followingPostDtos.get(Math.toIntExact(lastIdOfIndex)).getCreatedAt(),
94+
followingPostDtos
95+
.stream()
96+
.filter(post -> post.getPostId().equals(lastIdOfIndex))
97+
.findFirst()
98+
.get()
99+
.getSelectedDate(),
100+
followingPostDtos
101+
.stream()
102+
.filter(post -> post.getPostId().equals(lastIdOfIndex))
103+
.findFirst()
104+
.get()
105+
.getCreatedAt(),
96106
page).isEmpty();
97107

98108
return new CursorResult<>(followingPostDtos, hasNext);
@@ -145,10 +155,20 @@ public CursorResult<AllPostResponseDto> getAllPost(final Long myId, final Long u
145155
.map(post -> postConverter.toAllPostResponseDto(post, likeRepository.findByUserIdAndPost(myId, post)))
146156
.toList();
147157

148-
final Boolean hasNext = postRepository.findByUserAndSelectedDateLessThanAndCreatedAtLessThanOrderBySelectedDateDesc(
158+
final boolean hasNext = !postRepository.findByUserAndSelectedDateLessThanAndCreatedAtLessThanOrderBySelectedDateDesc(
149159
user,
150-
postList.get(Math.toIntExact(lastIdOfIndex)).getSelectedDate(),
151-
postList.get(Math.toIntExact(lastIdOfIndex)).getCreatedAt(),
160+
postList
161+
.stream()
162+
.filter(post -> post.getPostId().equals(lastIdOfIndex))
163+
.findFirst()
164+
.get()
165+
.getSelectedDate(),
166+
postList
167+
.stream()
168+
.filter(post -> post.getPostId().equals(lastIdOfIndex))
169+
.findFirst()
170+
.get()
171+
.getCreatedAt(),
152172
page).isEmpty();
153173

154174
return new CursorResult<>(posts, hasNext);
@@ -173,11 +193,21 @@ public CursorResult<AllPostResponseDto> getAllPostByCategory(final Long myId, fi
173193
.map(post -> postConverter.toAllPostResponseDto(post, likeRepository.findByUserIdAndPost(myId, post)))
174194
.toList();
175195

176-
final Boolean hasNext = postRepository.findByUserAndCategoryAndSelectedDateLessThanAndCreatedAtLessThanOrderBySelectedDateDesc(
196+
final boolean hasNext = !postRepository.findByUserAndCategoryAndSelectedDateLessThanAndCreatedAtLessThanOrderBySelectedDateDesc(
177197
user,
178198
category,
179-
postList.get(Math.toIntExact(lastIdOfIndex)).getSelectedDate(),
180-
postList.get(Math.toIntExact(lastIdOfIndex)).getCreatedAt(),
199+
postList
200+
.stream()
201+
.filter(post -> post.getPostId().equals(lastIdOfIndex))
202+
.findFirst()
203+
.get()
204+
.getSelectedDate(),
205+
postList
206+
.stream()
207+
.filter(post -> post.getPostId().equals(lastIdOfIndex))
208+
.findFirst()
209+
.get()
210+
.getCreatedAt(),
181211
page).isEmpty();
182212

183213
return new CursorResult<>(posts, hasNext);

โ€Žsrc/test/java/org/ahpuh/surf/post/repository/PostRepositoryTest.javaโ€Ž

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.junit.jupiter.api.Test;
1818
import org.springframework.beans.factory.annotation.Autowired;
1919
import org.springframework.boot.test.context.SpringBootTest;
20+
import org.springframework.data.domain.PageRequest;
2021
import org.springframework.transaction.annotation.Transactional;
2122

2223
import javax.persistence.EntityManager;
@@ -98,7 +99,7 @@ void setUp() {
9899
postRepository.save(Post.builder()
99100
.user(user2)
100101
.category(category1)
101-
.selectedDate(LocalDate.of(2020, 12, 12))
102+
.selectedDate(LocalDate.of(2021, 12, 12))
102103
.content("content1")
103104
.score(80)
104105
.build());
@@ -139,6 +140,7 @@ void setUp() {
139140
@Transactional
140141
void testQueryDsl() {
141142
final JPAQueryFactory query = new JPAQueryFactory(entityManager);
143+
final PageRequest page = PageRequest.of(0, 10);
142144
final List<FollowingPostDto> posts = query
143145
.select(new QFollowingPostDto(
144146
post.user.userId.as("userId"),
@@ -156,20 +158,24 @@ void testQueryDsl() {
156158
))
157159
.from(post)
158160
.leftJoin(follow).on(follow.user.userId.eq(userId1))
159-
.where(follow.followedUser.userId.eq(post.user.userId))
161+
.where(follow.followedUser.userId.eq(post.user.userId), post.isDeleted.eq(false))
160162
.groupBy(post.postId, follow.followId)
161-
.orderBy(post.updatedAt.desc())
163+
.orderBy(post.selectedDate.desc(), post.createdAt.desc())
164+
.limit(page.getPageSize())
162165
.fetch();
163166

164167
assertAll("followํ•œ ์‚ฌ์šฉ์ž์˜ ๋ชจ๋“  posts by querydsl",
165168
() -> assertThat(posts.size(), is(3)),
166-
() -> assertThat(posts.get(0).getContent(), is("content3")),
169+
() -> assertThat(posts.get(0).getContent(), is("content1")),
167170
() -> assertThat(posts.get(0).getUserId(), is(userId2)),
168-
() -> assertThat(posts.get(1).getContent(), is("content2")),
169-
() -> assertThat(posts.get(1).getUserId(), is(userId3)),
170-
() -> assertThat(posts.get(2).getContent(), is("content1")),
171-
() -> assertThat(posts.get(2).getUserId(), is(userId2))
171+
() -> assertThat(posts.get(1).getContent(), is("content3")),
172+
() -> assertThat(posts.get(1).getUserId(), is(userId2)),
173+
() -> assertThat(posts.get(2).getContent(), is("content2")),
174+
() -> assertThat(posts.get(2).getUserId(), is(userId3)),
175+
() -> assertThat(postRepository.findFollowingPosts(userId1, page).size(), is(3))
172176
);
177+
178+
;
173179
}
174180

175181
}

0 commit comments

Comments
ย (0)