Skip to content

Commit

Permalink
feat: contest 페이징 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
alexipharmical committed Aug 2, 2024
1 parent 2015832 commit 6e44e4c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,8 +25,8 @@ public class ContestController {
private final ContestService contestService;

@GetMapping("/all")
public ResponseData<List<ContestLoadRes>> getContests() {
return contestService.getContests();
public ResponseData<List<ContestLoadRes>> getContests(PageRequest pageRequest) {
return contestService.getContests(pageRequest);
}

@PostMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
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;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Transactional
Expand All @@ -28,11 +30,14 @@ public class ContestService {
private final GetCurrentMember getCurrentMember;

// 대회 전체 조회
public ResponseData<List<ContestLoadRes>> getContests() {
public ResponseData<List<ContestLoadRes>> getContests(PageRequest pageRequest) {
List<ContestEntity> contestList = contestRepository.findAll();
List<ContestLoadRes> contestLoadRes = contestList.stream().map(
ContestLoadRes :: of
).toList();

List<ContestLoadRes> contestLoadRes = contestList.stream()
.map(ContestLoadRes::of)
.skip((pageRequest.page() -1) * pageRequest.size())
.limit(pageRequest.size())
.collect(Collectors.toList());

return ResponseData.of(HttpStatus.OK, "대회 전체 조회 완료", contestLoadRes);
}
Expand Down

0 comments on commit 6e44e4c

Please sign in to comment.