From 6e44e4c2b4c65ca284df6b7ef1a36e6638dcec16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=98=B8=EC=A4=80?= Date: Fri, 2 Aug 2024 09:40:50 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20contest=20=ED=8E=98=EC=9D=B4=EC=A7=95?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../contest/controller/ContestController.java | 5 +++-- .../domain/contest/service/ContestService.java | 13 +++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) 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); }