-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/main/java/com/listywave/user/application/dto/FollowersResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.listywave.user.application.dto; | ||
|
||
import com.listywave.user.application.domain.User; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record FollowersResponse( | ||
List<FollowerInfo> followers, | ||
int totalCount, | ||
Long cursorId, | ||
boolean hasNext | ||
) { | ||
|
||
public static FollowersResponse of(List<User> users, int totalCount, boolean hasNext) { | ||
return FollowersResponse.builder() | ||
.followers(FollowerInfo.toList(users)) | ||
.totalCount(totalCount) | ||
.cursorId(users.get(users.size() - 1).getId()) | ||
.hasNext(hasNext) | ||
.build(); | ||
} | ||
|
||
public static FollowersResponse empty() { | ||
return FollowersResponse.builder() | ||
.followers(Collections.emptyList()) | ||
.totalCount(0) | ||
.hasNext(false) | ||
.build(); | ||
} | ||
} | ||
|
||
@Builder | ||
record FollowerInfo( | ||
Long id, | ||
String nickname, | ||
String profileImageUrl | ||
) { | ||
|
||
public static List<FollowerInfo> toList(List<User> users) { | ||
return users.stream() | ||
.map(FollowerInfo::of) | ||
.toList(); | ||
} | ||
|
||
public static FollowerInfo of(User user) { | ||
return FollowerInfo.builder() | ||
.id(user.getId()) | ||
.nickname(user.getNickname()) | ||
.profileImageUrl(user.getProfileImageUrl()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/com/listywave/user/repository/follow/custom/CustomFollowRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.listywave.user.repository.follow.custom; | ||
|
||
import com.listywave.user.application.domain.Follow; | ||
import com.listywave.user.application.domain.User; | ||
import java.util.List; | ||
|
||
public interface CustomFollowRepository { | ||
|
||
List<Follow> findAllByFollowingUser(User user, int size, int cursorId); | ||
} |
28 changes: 28 additions & 0 deletions
28
...ain/java/com/listywave/user/repository/follow/custom/impl/CustomFollowRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.listywave.user.repository.follow.custom.impl; | ||
|
||
import static com.listywave.user.application.domain.QFollow.follow; | ||
|
||
import com.listywave.user.application.domain.Follow; | ||
import com.listywave.user.application.domain.User; | ||
import com.listywave.user.repository.follow.custom.CustomFollowRepository; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class CustomFollowRepositoryImpl implements CustomFollowRepository { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public List<Follow> findAllByFollowingUser(User followingUser, int size, int cursorId) { | ||
return queryFactory.selectFrom(follow) | ||
.where( | ||
follow.followingUser.eq(followingUser), | ||
follow.followingUser.id.gt(cursorId) | ||
) | ||
.orderBy(follow.createdDate.desc()) | ||
.limit(size + 1) | ||
.fetch(); | ||
} | ||
} |