Skip to content

Commit

Permalink
merge dev into main (#497)
Browse files Browse the repository at this point in the history
Co-authored-by: hannkim <skqkdldhf98@gmail.com>
Co-authored-by: yoahn <46748334+AYoungSn@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 10, 2024
1 parent bde4915 commit d627ca5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand All @@ -37,7 +39,7 @@ public ExpRankPageResponseDto getExpRankPage(@Valid PageRequestDto pageRequestDt
*/
@GetMapping("/ranks/{gameType}")
public RankPageResponseDto getRankPage(@Valid PageRequestDto pageRequestDto, @Parameter(hidden = true) @Login UserDto user,
Long season, String gameType){
@RequestParam Long season, @PathVariable String gameType){
PageRequest pageRequest = PageRequest.of(pageRequestDto.getPage() - 1, pageRequestDto.getSize());
return rankService.getRankPageV2(pageRequest, user, season);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public interface RankRepository extends JpaRepository<Rank, Long> {
+ " GROUP BY p.user_id) pg "
+ "ON pg.user_id = u.id "
+ "WHERE r.season_id = :seasonId AND (r.losses > 0 OR r.wins > 0) "
+ "LIMIT :pageSize OFFSET :pageNum ", nativeQuery = true)
List<RankV2Dto> findPppRankBySeasonId(@Param("pageNum")int pageNum, @Param("pageSize")int pageSize, @Param("seasonId") Long seasonId);
+ "LIMIT :limit OFFSET :offset ", nativeQuery = true)
List<RankV2Dto> findPppRankBySeasonId(@Param("offset")int offset, @Param("limit")int limit, @Param("seasonId") Long seasonId);

@Query(value = "SELECT count(*) "
+ "FROM Ranks r "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ public ExpRankPageResponseDto getExpRankPage(PageRequest pageRequest, UserDto cu
users.getTotalPages(),
expRankDtos);
}

@Cacheable(value = "expRanking", cacheManager = "gameCacheManager",
key = "#pageRequest.pageNumber + #pageRequest.pageSize")
public List<ExpRankDto> getExpRankList(PageRequest pageRequest) {
Season curSeason = seasonFindService.findCurrentSeason(LocalDateTime.now());
List<ExpRankV2Dto> expRankV2Dtos = userRepository.findExpRank(pageRequest.getPageNumber(), pageRequest.getPageSize(), curSeason.getId());
int pageOffset = pageRequest.getPageNumber() * pageRequest.getPageSize();
List<ExpRankV2Dto> expRankV2Dtos = userRepository.findExpRank(pageOffset, pageRequest.getPageSize(), curSeason.getId());
return expRankV2Dtos.stream().map(ExpRankDto::from).collect(Collectors.toList());
}

Expand Down Expand Up @@ -119,7 +121,8 @@ public RankPageResponseDto getRankPageV2(PageRequest pageRequest, UserDto curUse

int myRank = rankRepository.findRankByUserIdAndSeasonId(curUser.getId(), season.getId())
.orElse(-1);
List<RankDto> rankList = rankRepository.findPppRankBySeasonId(pageRequest.getPageNumber(), pageRequest.getPageSize(), season.getId())
int pageOffset = pageRequest.getPageNumber() * pageRequest.getPageSize();
List<RankDto> rankList = rankRepository.findPppRankBySeasonId(pageOffset, pageRequest.getPageSize(), season.getId())
.stream().map(RankDto::from).collect(Collectors.toList());
return new RankPageResponseDto(myRank, pageRequest.getPageNumber() + 1, totalPage, rankList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public interface UserRepository extends JpaRepository<User, Long> {
+ "FROM User u LEFT JOIN Ranks r "
+ "ON u.id = r.user_id "
+ "WHERE r.season_id = :seasonId AND u.total_exp > 0 "
+ "LIMIT :pageSize OFFSET :pageNum", nativeQuery = true)
List<ExpRankV2Dto> findExpRank(@Param("pageNum")int pageNum, @Param("pageSize")int pageSize, @Param("seasonId")Long seasonId);
+ "LIMIT :limit OFFSET :offset", nativeQuery = true)
List<ExpRankV2Dto> findExpRank(@Param("offset")int offset, @Param("limit")int limit, @Param("seasonId")Long seasonId);

}

0 comments on commit d627ca5

Please sign in to comment.