Skip to content

Commit c69beee

Browse files
committed
feature: 팔로우/팔로잉 조회 시 키워드로 검색 가능하도록 변경
1 parent 8512cc0 commit c69beee

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

src/main/java/com/example/log4u/domain/follow/repository/FollowQuerydsl.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,26 @@ private NumberPath<Long> getNumberPath(boolean isFollowTarget) {
2929
return isFollowTarget ? follow.targetId : follow.initiatorId;
3030
}
3131

32-
private BooleanBuilder getBooleanBuilder(boolean isFollowTarget, Long userId, Long cursorId) {
32+
private BooleanBuilder getBooleanBuilder(boolean isFollowTarget, Long userId, Long cursorId, String keyword) {
3333
BooleanBuilder builder = new BooleanBuilder();
34-
builder.and(getNumberPath(isFollowTarget).eq(userId));
34+
NumberPath<Long> numberPath = getNumberPath(isFollowTarget);
35+
36+
builder.and(numberPath.eq(userId));
3537

3638
if (cursorId != null) {
3739
builder.and(follow.id.lt(cursorId));
3840
}
3941

42+
if (keyword != null) {
43+
builder.and(user.nickname.like(keyword));
44+
}
45+
4046
return builder;
4147
}
4248

43-
private List<UserThumbnailResponseDto> getContent(boolean isFollowTarget, Long userId, Long cursorId) {
44-
BooleanBuilder builder = getBooleanBuilder(isFollowTarget, userId, cursorId);
49+
private List<UserThumbnailResponseDto> getContent(boolean isFollowTarget, Long userId, Long cursorId,
50+
String keyword) {
51+
BooleanBuilder builder = getBooleanBuilder(isFollowTarget, userId, cursorId, keyword);
4552

4653
NumberPath<Long> numberPath = getNumberPath(isFollowTarget);
4754

@@ -58,16 +65,18 @@ private List<UserThumbnailResponseDto> getContent(boolean isFollowTarget, Long u
5865
}
5966

6067
//내 팔로워 아이디 슬라이스
61-
public Slice<UserThumbnailResponseDto> getFollowerSliceByUserId(Long userId, Long cursorId, Pageable pageable) {
68+
public Slice<UserThumbnailResponseDto> getFollowerSliceByUserId(Long userId, Long cursorId, String keyword,
69+
Pageable pageable) {
6270
boolean isFollowTarget = true;
63-
List<UserThumbnailResponseDto> content = getContent(isFollowTarget, userId, cursorId);
71+
List<UserThumbnailResponseDto> content = getContent(isFollowTarget, userId, cursorId, keyword);
6472
return PageableUtil.checkAndCreateSlice(content, pageable);
6573
}
6674

6775
// 내가 팔로잉하는 아이디 슬라이스
68-
public Slice<UserThumbnailResponseDto> getFollowingSliceByUserId(Long userId, Long cursorId, Pageable pageable) {
76+
public Slice<UserThumbnailResponseDto> getFollowingSliceByUserId(Long userId, Long cursorId, String keyword,
77+
Pageable pageable) {
6978
boolean isFollowTarget = false;
70-
List<UserThumbnailResponseDto> content = getContent(isFollowTarget, userId, cursorId);
79+
List<UserThumbnailResponseDto> content = getContent(isFollowTarget, userId, cursorId, keyword);
7180
return PageableUtil.checkAndCreateSlice(content, pageable);
7281
}
7382
}

src/main/java/com/example/log4u/domain/user/mypage/controller/MyPageController.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,22 @@ public ResponseEntity<PageResponse<DiaryResponseDto>> getMyLikesPage(
4343
@GetMapping("/users/me/followings")
4444
public ResponseEntity<PageResponse<UserThumbnailResponseDto>> getMyFollowingPage(
4545
@AuthenticationPrincipal CustomOAuth2User customOAuth2User,
46-
@RequestParam(required = false) Long cursorId
46+
@RequestParam(required = false) Long cursorId,
47+
@RequestParam(required = false) String keyword
48+
4749
) {
4850
long userId = customOAuth2User.getUserId();
49-
return ResponseEntity.ok(myPageService.getMyFollowings(userId, cursorId));
51+
return ResponseEntity.ok(myPageService.getMyFollowings(userId, cursorId, keyword));
5052
}
5153

5254
@GetMapping("/users/me/followers")
5355
public ResponseEntity<PageResponse<UserThumbnailResponseDto>> getMyFollowerPage(
5456
@AuthenticationPrincipal CustomOAuth2User customOAuth2User,
55-
@RequestParam(required = false) Long cursorId
57+
@RequestParam(required = false) Long cursorId,
58+
@RequestParam(required = false) String keyword
5659
) {
5760
long userId = customOAuth2User.getUserId();
58-
return ResponseEntity.ok(myPageService.getMyFollowers(userId, cursorId));
61+
return ResponseEntity.ok(myPageService.getMyFollowers(userId, cursorId, keyword));
5962
}
6063

6164
@GetMapping("/users/me/subscriptions")

src/main/java/com/example/log4u/domain/user/mypage/service/MyPageService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ public PageResponse<DiaryResponseDto> getLikeDiariesByCursor(Long userId, Long c
4444
}
4545

4646
@Transactional(readOnly = true)
47-
public PageResponse<UserThumbnailResponseDto> getMyFollowers(Long userId, Long cursorId) {
47+
public PageResponse<UserThumbnailResponseDto> getMyFollowers(Long userId, Long cursorId, String keyword) {
4848
Slice<UserThumbnailResponseDto> slice = followQuerydsl.getFollowerSliceByUserId(
4949
userId,
5050
cursorId,
51+
keyword,
5152
PageRequest.of(0, defaultPageSize));
5253

5354
Long nextCursor = !slice.isEmpty() ? slice.getContent().getLast().userId() : null;
@@ -56,10 +57,11 @@ public PageResponse<UserThumbnailResponseDto> getMyFollowers(Long userId, Long c
5657
}
5758

5859
@Transactional(readOnly = true)
59-
public PageResponse<UserThumbnailResponseDto> getMyFollowings(Long userId, Long cursorId) {
60+
public PageResponse<UserThumbnailResponseDto> getMyFollowings(Long userId, Long cursorId, String keyword) {
6061
Slice<UserThumbnailResponseDto> slice = followQuerydsl.getFollowingSliceByUserId(
6162
userId,
6263
cursorId,
64+
keyword,
6365
PageRequest.of(0, defaultPageSize));
6466

6567
Long nextCursor = !slice.isEmpty() ? slice.getContent().getLast().userId() : null;

src/test/java/com/example/log4u/domain/user/mypage/service/MyPageServiceTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ void getLikeDiariesByCursor_returnsCorrectData() {
9494
void getMyFollowers_returnsCorrectData() {
9595
var slice = new SliceImpl<>(List.of(new UserThumbnailResponseDto(userId, "nick", "image")));
9696

97-
when(followQuerydsl.getFollowerSliceByUserId(eq(userId), eq(cursorId), any(PageRequest.class)))
97+
when(followQuerydsl.getFollowerSliceByUserId(eq(userId), eq(cursorId), any(), any(PageRequest.class)))
9898
.thenReturn(slice);
9999

100-
PageResponse<UserThumbnailResponseDto> result = myPageService.getMyFollowers(userId, cursorId);
100+
PageResponse<UserThumbnailResponseDto> result = myPageService.getMyFollowers(userId, cursorId, null);
101101

102102
assertThat(result).isNotNull();
103103
}
@@ -107,10 +107,10 @@ void getMyFollowers_returnsCorrectData() {
107107
void getMyFollowings_returnsCorrectData() {
108108
var slice = new SliceImpl<>(List.of(new UserThumbnailResponseDto(userId, "nick", "image")));
109109

110-
when(followQuerydsl.getFollowingSliceByUserId(eq(userId), eq(cursorId), any(PageRequest.class)))
110+
when(followQuerydsl.getFollowingSliceByUserId(eq(userId), eq(cursorId), any(), any(PageRequest.class)))
111111
.thenReturn(slice);
112112

113-
PageResponse<UserThumbnailResponseDto> result = myPageService.getMyFollowings(userId, cursorId);
113+
PageResponse<UserThumbnailResponseDto> result = myPageService.getMyFollowings(userId, cursorId, null);
114114

115115
assertThat(result).isNotNull();
116116
}

0 commit comments

Comments
 (0)