Skip to content

Commit

Permalink
fix: totalPageSize response 추가 (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
gunom authored Dec 28, 2023
2 parents b2ce2d1 + 68e1dc0 commit 92f813a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public List<Long> getPokeFriendIds(Long userId) {
public List<PokeHistory> getAllPokedHistoryOrderByMostRecent(Long userId) {
return pokeHistoryRepository.findAllByPokedIdAndIsReplyIsFalseOrderByCreatedAtDesc(userId);
}

public Page<PokeHistory> getAllPokedHistoryOrderByMostRecent(Long userId, Pageable pageable) {
return pokeHistoryRepository.findAllByPokedIdAndIsReplyIsFalseOrderByCreatedAtDesc(userId, pageable);
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/sopt/app/facade/PokeFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,16 @@ public List<SimplePokeProfile> getAllPokeMeHistory(User user) {
@Transactional(readOnly = true)
public PokeToMeHistoryList getAllPokeMeHistory(User user, Pageable pageable) {
Page<PokeHistory> pokedHistories = pokeHistoryService.getAllPokedHistoryOrderByMostRecent(user.getId(), pageable);
val size = pokeHistoryService.getAllPokedHistoryOrderByMostRecent(user.getId()).size();
val totalPageSize = size / pageable.getPageSize();
List<SimplePokeProfile> pokeToMeHistories = pokedHistories.stream()
.filter(pokeHistory -> !pokeHistory.getIsReply())
.map(pokeHistory -> getPokeHistoryProfile(user, pokeHistory.getPokerId(), pokeHistory.getId()))
.distinct()
.toList();
return PokeToMeHistoryList.of(
pokeToMeHistories,
totalPageSize,
pageable.getPageSize(),
pokedHistories.getNumber()
);
Expand Down Expand Up @@ -258,11 +261,11 @@ public EachRelationFriendList getAllFriendByFriendship(User user, Friendship fri
}).toList();
val totalSize = friendService.findAllFriendSizeByFriendship(
user.getId(), friendship.getLowerLimit(), friendship.getUpperLimit());
val totalPageSize = totalSize / pageable.getPageSize();
return EachRelationFriendList.of(
allOfPokeWithFriends,
totalSize,
// TODO: 여기서 필요한 PageSize의 값이 조회 결과 리스트의 Elements Size 인지,
// 이후 API 재호출 시 사용할 RequestParam 값을 위해 넣어주는 건지 논의
totalPageSize,
pageable.getPageSize(),
friends.getNumber()
);
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/org/sopt/app/presentation/poke/PokeResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,19 @@ public static class EachRelationFriendList implements FriendList{
private List<SimplePokeProfile> friendList;
@Schema(description = "친구 수", example = "1")
private int totalSize;
@Schema(description = "전체 페이지 사이즈", example = "1")
private int totalPageSize;
@Schema(description = "페이지 사이즈", example = "1")
private int pageSize;
@Schema(description = "페이지 번호", example = "1")
private int pageNum;


public static EachRelationFriendList of(
List<SimplePokeProfile> friendList, int totalSize, int pageSize, int pageNum
List<SimplePokeProfile> friendList, int totalSize, int totalPageSize, int pageSize, int pageNum
) {
return new EachRelationFriendList(
friendList, totalSize, pageSize, pageNum
friendList, totalSize, totalPageSize, pageSize, pageNum
);
}

Expand All @@ -93,14 +96,15 @@ public static EachRelationFriendList of(
public static class PokeToMeHistoryList implements HistoryList{

private List<SimplePokeProfile> history;
private int totalPageSize;
private Integer pageSize;
private Integer pageNum;

public static PokeToMeHistoryList of(
List<SimplePokeProfile> history, Integer pageSize, Integer pageNum
List<SimplePokeProfile> history, int totalPageSize, Integer pageSize, Integer pageNum
) {
return new PokeToMeHistoryList(
history, pageSize, pageNum
history, totalPageSize, pageSize, pageNum
);
}

Expand Down

0 comments on commit 92f813a

Please sign in to comment.