diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/controller/ContestController.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/controller/ContestController.java index 36b6a38..eb4109f 100644 --- a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/controller/ContestController.java +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/controller/ContestController.java @@ -3,6 +3,7 @@ import kr.hs.dgsw.SOPO_server_v2.domain.contest.dto.ContestLoadRes; import kr.hs.dgsw.SOPO_server_v2.domain.contest.dto.ContestUpdateReq; import kr.hs.dgsw.SOPO_server_v2.domain.contest.service.ContestService; +import kr.hs.dgsw.SOPO_server_v2.global.page.PageRequest; import kr.hs.dgsw.SOPO_server_v2.global.response.Response; import kr.hs.dgsw.SOPO_server_v2.global.response.ResponseData; import lombok.RequiredArgsConstructor; @@ -24,8 +25,8 @@ public class ContestController { private final ContestService contestService; @GetMapping("/all") - public ResponseData> getContests() { - return contestService.getContests(); + public ResponseData> getContests(PageRequest pageRequest) { + return contestService.getContests(pageRequest); } @PostMapping diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/service/ContestService.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/service/ContestService.java index bc08113..5036c72 100644 --- a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/service/ContestService.java +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/service/ContestService.java @@ -11,6 +11,7 @@ import kr.hs.dgsw.SOPO_server_v2.global.error.custom.contest.ContestNotFound; import kr.hs.dgsw.SOPO_server_v2.global.error.custom.member.MemberNotCoincideException; import kr.hs.dgsw.SOPO_server_v2.global.infra.security.GetCurrentMember; +import kr.hs.dgsw.SOPO_server_v2.global.page.PageRequest; import kr.hs.dgsw.SOPO_server_v2.global.response.Response; import kr.hs.dgsw.SOPO_server_v2.global.response.ResponseData; import lombok.RequiredArgsConstructor; @@ -18,6 +19,7 @@ import org.springframework.stereotype.Service; import java.util.List; +import java.util.stream.Collectors; @Service @Transactional @@ -28,11 +30,14 @@ public class ContestService { private final GetCurrentMember getCurrentMember; // 대회 전체 조회 - public ResponseData> getContests() { + public ResponseData> getContests(PageRequest pageRequest) { List contestList = contestRepository.findAll(); - List contestLoadRes = contestList.stream().map( - ContestLoadRes :: of - ).toList(); + + List contestLoadRes = contestList.stream() + .map(ContestLoadRes::of) + .skip((pageRequest.page() -1) * pageRequest.size()) + .limit(pageRequest.size()) + .collect(Collectors.toList()); return ResponseData.of(HttpStatus.OK, "대회 전체 조회 완료", contestLoadRes); }