From 84fe06aae7594e9b998d9eb9b049521d699f6f4b Mon Sep 17 00:00:00 2001 From: Khyojun Date: Mon, 11 Nov 2024 02:19:29 +0900 Subject: [PATCH] =?UTF-8?q?hotfix=20:=20region,=20school=20pagination=20?= =?UTF-8?q?=EB=B0=8F=20=EB=AC=B4=ED=95=9C=20=EC=8A=A4=ED=81=AC=EB=A1=A4=20?= =?UTF-8?q?=EC=A0=95=EC=83=81=20=EB=8F=99=EC=9E=91=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/UserPageListByRegionResponseDto.java | 10 +++++++--- .../api/regionPage/service/RegionRankService.java | 14 +++++++++----- .../dto/UserPageListBySchoolResponseDto.java | 6 +++--- .../api/schoolPage/service/SchoolRankService.java | 11 ++++++----- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/main/java/gitbal/backend/api/regionPage/dto/UserPageListByRegionResponseDto.java b/src/main/java/gitbal/backend/api/regionPage/dto/UserPageListByRegionResponseDto.java index 4b88c5e..6f61c35 100644 --- a/src/main/java/gitbal/backend/api/regionPage/dto/UserPageListByRegionResponseDto.java +++ b/src/main/java/gitbal/backend/api/regionPage/dto/UserPageListByRegionResponseDto.java @@ -3,8 +3,10 @@ import java.util.List; import lombok.Builder; import lombok.Data; +import lombok.extern.slf4j.Slf4j; @Data +@Slf4j public class UserPageListByRegionResponseDto { private List userInfoByRegion; private int currentPage; @@ -26,11 +28,13 @@ public UserPageListByRegionResponseDto(List userInfoByRegion, return; } - int pageSize = 10; + log.info("totalCount : {}", totalCount); + + int pageSize = 14; this.totalPages = (int) Math.ceil((double) totalCount / pageSize); - this.end = (int) (Math.ceil(page / 10.0)) * 10; - this.start = end - 9; + this.end = (int) (Math.ceil(page / 14.0)) * 14; + this.start = end - 13; int last = (int) (Math.ceil(totalCount / (double) pageSize)); end = end > last ? last : end; diff --git a/src/main/java/gitbal/backend/api/regionPage/service/RegionRankService.java b/src/main/java/gitbal/backend/api/regionPage/service/RegionRankService.java index 767f4c9..fe43fd6 100644 --- a/src/main/java/gitbal/backend/api/regionPage/service/RegionRankService.java +++ b/src/main/java/gitbal/backend/api/regionPage/service/RegionRankService.java @@ -23,6 +23,7 @@ import java.util.Objects; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -35,6 +36,7 @@ @Service @RequiredArgsConstructor +@Slf4j public class RegionRankService { private static final int PAGE_SIZE = 14; @@ -107,10 +109,11 @@ public UserPageListByRegionResponseDto getUserListByRegionName(int page, String Pageable pageable = initpageable(page, "score"); Page userByRegionName = userRepository.findUserByRegion_RegionName(regionName, pageable); + log.info("userByRegionName: {}", userByRegionName.getTotalPages()); if (userByRegionName.getTotalPages() < page) throw new PageOutOfRangeException(); List userInfoByRegions = convertPageByUserInfoByRegion( - userByRegionName); + userByRegionName, page); return buildUserPageListByRegionResponseDto(page, userInfoByRegions, userByRegionName); } catch (Exception e) { if (Objects.isNull(e.getMessage())) @@ -120,12 +123,13 @@ public UserPageListByRegionResponseDto getUserListByRegionName(int page, String } - private List convertPageByUserInfoByRegion(Page userBySchoolName) { + private List convertPageByUserInfoByRegion(Page userBySchoolName, int page) { List users = userBySchoolName.get().toList(); List userInfoByRegions= new ArrayList<>(); - for(int index=0; index userInfoBySchools, return; } - int pageSize = 10; + int pageSize = 14; this.totalPages = (int) Math.ceil((double) totalCount / pageSize); - this.end = (int) (Math.ceil(page / 10.0)) * 10; - this.start = end - 9; + this.end = (int) (Math.ceil(page / 14.0)) * 14; + this.start = end - 13; int last = (int) (Math.ceil(totalCount / (double) pageSize)); end = end > last ? last : end; diff --git a/src/main/java/gitbal/backend/api/schoolPage/service/SchoolRankService.java b/src/main/java/gitbal/backend/api/schoolPage/service/SchoolRankService.java index ef0df42..6ddc8bd 100644 --- a/src/main/java/gitbal/backend/api/schoolPage/service/SchoolRankService.java +++ b/src/main/java/gitbal/backend/api/schoolPage/service/SchoolRankService.java @@ -125,7 +125,7 @@ public UserPageListBySchoolResponseDto getUserListBySchoolName(int page, String throw new PageOutOfRangeException(); List userInfoBySchools = convertPageByUserInfoBySchool( - userBySchoolName); + userBySchoolName, page); log.info("userBySchoolName : {}",userInfoBySchools); return buildUserPageListBySchoolResponseDto(page, userInfoBySchools, userBySchoolName); @@ -141,12 +141,13 @@ private boolean isPresentSchoolName(String schoolName) { return schoolRepository.findBySchoolName(schoolName).isPresent(); } - private List convertPageByUserInfoBySchool(Page userBySchoolName) { + private List convertPageByUserInfoBySchool(Page userBySchoolName, int page) { List users = userBySchoolName.get().toList(); List userInfoBySchools = new ArrayList<>(); - for (int index = 0; index < users.size(); index++) { - User user = users.get(index); - UserInfoBySchool userInfo = convertToUserInfoBySchool(user, index+1); + int startNum = (page-1) * PAGE_SIZE +1; + for (int index = startNum; index < users.size()+startNum; index++) { + User user = users.get(index-startNum); + UserInfoBySchool userInfo = convertToUserInfoBySchool(user, index); userInfoBySchools.add(userInfo); } return userInfoBySchools;