Skip to content

Commit

Permalink
Merge pull request #133 from kakao-tech-campus-2nd-step3/Develop
Browse files Browse the repository at this point in the history
[Master] fix : pageable에 totalpage 추가
  • Loading branch information
minsu-cnu authored Nov 10, 2024
2 parents 1dfe252 + f184684 commit b8ca305
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import team18.team18_be.auth.entity.User;
import team18.team18_be.config.resolver.LoginUser;
import team18.team18_be.recruitment.dto.request.RecruitmentRequest;
import team18.team18_be.recruitment.dto.response.RecruitmentAllResponse;
import team18.team18_be.recruitment.dto.response.RecruitmentResponse;
import team18.team18_be.recruitment.dto.response.RecruitmentResponseForCompany;
import team18.team18_be.recruitment.dto.response.RecruitmentSummationResponse;
Expand Down Expand Up @@ -46,7 +47,7 @@ public ResponseEntity<Void> saveRecruitment(

@Operation(summary = "구인글 전체 조회 메서드")
@GetMapping
public ResponseEntity<List<RecruitmentSummationResponse>> getAllRecruitments(
public ResponseEntity<RecruitmentAllResponse> getAllRecruitments(
@RequestParam int page
) {
int fixedPageSize = 4;
Expand Down Expand Up @@ -83,7 +84,7 @@ public ResponseEntity<Void> setRecruitmentHiringFalse(

@Operation(summary = "최근 올라온 구인글 순서대로 정렬")
@GetMapping("/latestRegistration")
public ResponseEntity<List<RecruitmentSummationResponse>> getAllRecruitmentsLatestRegistration(
public ResponseEntity<RecruitmentAllResponse> getAllRecruitmentsLatestRegistration(
@RequestParam int page
) {
int fixedPageSize = 4;
Expand All @@ -93,7 +94,7 @@ public ResponseEntity<List<RecruitmentSummationResponse>> getAllRecruitmentsLate

@Operation(summary = "급여 높은 순서대로 정리해서 전체 구인글 반환하는 메서드")
@GetMapping("/salary")
public ResponseEntity<List<RecruitmentSummationResponse>> getAllRecruitmentsSalary(
public ResponseEntity<RecruitmentAllResponse> getAllRecruitmentsSalary(
@RequestParam int page
) {
int fixedPageSize = 4;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package team18.team18_be.recruitment.dto.response;

public record PageDto(
Integer totalPage
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package team18.team18_be.recruitment.dto.response;

import java.util.List;

public record RecruitmentAllResponse(
List<RecruitmentSummationResponse> content,
PageDto pageable
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.springframework.stereotype.Service;
import team18.team18_be.config.infrastructure.OpenAiService;
import team18.team18_be.recruitment.dto.request.RecruitmentRequest;
import team18.team18_be.recruitment.dto.response.PageDto;
import team18.team18_be.recruitment.dto.response.RecruitmentAllResponse;
import team18.team18_be.recruitment.dto.response.RecruitmentResponse;
import team18.team18_be.recruitment.dto.response.RecruitmentResponseForCompany;
import team18.team18_be.recruitment.dto.response.RecruitmentSummationResponse;
Expand Down Expand Up @@ -58,9 +60,10 @@ public void saveRecruitment(RecruitmentRequest recruitmentRequest)

}

public List<RecruitmentSummationResponse> getAllRecruitment(Pageable pageable) {
public RecruitmentAllResponse getAllRecruitment(Pageable pageable) {
Page<Recruitment> recruitments = recruitmentRepository.findAllByHiringTrue(pageable);
return recruitments.stream()
List<RecruitmentSummationResponse> recruitmentSummationResponseList =
recruitments.stream()
.map(recruitment -> new RecruitmentSummationResponse(
recruitment.getRecruitmentId(),
recruitment.getCompany().getLogoImage(),
Expand All @@ -71,38 +74,46 @@ public List<RecruitmentSummationResponse> getAllRecruitment(Pageable pageable) {
recruitment.getArea()
))
.collect(Collectors.toList());
int totalPage = recruitments.getTotalPages();
return new RecruitmentAllResponse(recruitmentSummationResponseList,new PageDto(totalPage));
}

public List<RecruitmentSummationResponse> getAllRecruitmentAndSortBySalary(Pageable pageable) {
public RecruitmentAllResponse getAllRecruitmentAndSortBySalary(Pageable pageable) {
Page<Recruitment> recruitments = recruitmentRepository.findAllByHiringTrueOrderBySalaryDesc(
pageable);
return recruitments.stream()
.map(recruitment -> new RecruitmentSummationResponse(
recruitment.getRecruitmentId(),
recruitment.getCompany().getLogoImage(),
recruitment.getKoreanTitle(),
recruitment.getVietnameseTitle(),
recruitment.getCompanyName(),
recruitment.getSalary(),
recruitment.getArea()
))
.collect(Collectors.toList());
List<RecruitmentSummationResponse> recruitmentSummationResponseList =
recruitments.stream()
.map(recruitment -> new RecruitmentSummationResponse(
recruitment.getRecruitmentId(),
recruitment.getCompany().getLogoImage(),
recruitment.getKoreanTitle(),
recruitment.getVietnameseTitle(),
recruitment.getCompanyName(),
recruitment.getSalary(),
recruitment.getArea()
))
.collect(Collectors.toList());
int totalPage = recruitments.getTotalPages();
return new RecruitmentAllResponse(recruitmentSummationResponseList,new PageDto(totalPage));
}

public List<RecruitmentSummationResponse> getAllRecruitmentAndSortByDate(Pageable pageable) {
public RecruitmentAllResponse getAllRecruitmentAndSortByDate(Pageable pageable) {
Page<Recruitment> recruitments = recruitmentRepository.findAllByHiringTrueOrderByUploadDateDesc(
pageable);
return recruitments.stream()
.map(recruitment -> new RecruitmentSummationResponse(
recruitment.getRecruitmentId(),
recruitment.getCompany().getLogoImage(),
recruitment.getKoreanTitle(),
recruitment.getVietnameseTitle(),
recruitment.getCompanyName(),
recruitment.getSalary(),
recruitment.getArea()
))
.collect(Collectors.toList());
List<RecruitmentSummationResponse> recruitmentSummationResponseList =
recruitments.stream()
.map(recruitment -> new RecruitmentSummationResponse(
recruitment.getRecruitmentId(),
recruitment.getCompany().getLogoImage(),
recruitment.getKoreanTitle(),
recruitment.getVietnameseTitle(),
recruitment.getCompanyName(),
recruitment.getSalary(),
recruitment.getArea()
))
.collect(Collectors.toList());
int totalPage = recruitments.getTotalPages();
return new RecruitmentAllResponse(recruitmentSummationResponseList,new PageDto(totalPage));
}

public RecruitmentResponse getRecruitmentResponseByRecruitmentId(Long userId) {
Expand Down

0 comments on commit b8ca305

Please sign in to comment.