From 5d7f01973cddad3a04f039e12cbc05ddd6bb1e13 Mon Sep 17 00:00:00 2001 From: Sin Ye Rin <91180366+nyeroni@users.noreply.github.com> Date: Mon, 14 Oct 2024 15:59:55 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=B7=A8=EC=97=85=EB=A5=A0=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20=ED=98=95=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ....java => EmploymentRateApiController.java} | 16 +++++-- .../service/EmploymentRateService.java | 47 ++++++++++++++++--- 2 files changed, 53 insertions(+), 10 deletions(-) rename src/main/java/yerong/wedle/employmentRate/controller/{EmploymentRateController.java => EmploymentRateApiController.java} (73%) diff --git a/src/main/java/yerong/wedle/employmentRate/controller/EmploymentRateController.java b/src/main/java/yerong/wedle/employmentRate/controller/EmploymentRateApiController.java similarity index 73% rename from src/main/java/yerong/wedle/employmentRate/controller/EmploymentRateController.java rename to src/main/java/yerong/wedle/employmentRate/controller/EmploymentRateApiController.java index 6ce228c..90bbaad 100644 --- a/src/main/java/yerong/wedle/employmentRate/controller/EmploymentRateController.java +++ b/src/main/java/yerong/wedle/employmentRate/controller/EmploymentRateApiController.java @@ -8,8 +8,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import yerong.wedle.competitionRate.dto.CompetitionRateResponse; -import yerong.wedle.employmentRate.dto.EmploymentRateResponse; import yerong.wedle.employmentRate.dto.UniversityEmploymentRateResponse; import yerong.wedle.employmentRate.service.EmploymentRateService; @@ -19,7 +17,7 @@ @RequiredArgsConstructor @RestController @RequestMapping("/api/employment-rate") -public class EmploymentRateController { +public class EmploymentRateApiController { private final EmploymentRateService employmentRateService; @Operation( @@ -27,7 +25,7 @@ public class EmploymentRateController { description = "대학교 ID를 이용해 해당 대학교의 취업률 삼년치를 조회합니다." ) @GetMapping() - public ResponseEntity getAllEmploymentRates(@RequestParam Long universityId) { + public ResponseEntity getEmploymentRatesByUniversity(@RequestParam Long universityId) { UniversityEmploymentRateResponse universityEmploymentRates = employmentRateService.getUniversityEmploymentRates(universityId); return ResponseEntity.ok(universityEmploymentRates); } @@ -41,4 +39,14 @@ public ResponseEntity> getTop5Universitie List top5UniversitiesEmploymentRates = employmentRateService.getTop5UniversitiesEmploymentRates(); return ResponseEntity.ok(top5UniversitiesEmploymentRates); } + + @Operation( + summary = "모든 대학교 취업률 조회", + description = "모든 대학교의 취업률을 조회합니다." + ) + @GetMapping("/all") + public ResponseEntity> getAllUniversityEmploymentRates () { + List UniversitiesEmploymentRates = employmentRateService.getAllUniversityEmploymentRates(); + return ResponseEntity.ok(UniversitiesEmploymentRates); + } } diff --git a/src/main/java/yerong/wedle/employmentRate/service/EmploymentRateService.java b/src/main/java/yerong/wedle/employmentRate/service/EmploymentRateService.java index bcb569f..fe5b3bd 100644 --- a/src/main/java/yerong/wedle/employmentRate/service/EmploymentRateService.java +++ b/src/main/java/yerong/wedle/employmentRate/service/EmploymentRateService.java @@ -17,6 +17,7 @@ import yerong.wedle.university.repository.UniversityRepository; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; @Service @@ -47,14 +48,36 @@ public UniversityEmploymentRateResponse getUniversityEmploymentRates(Long univer @Transactional(readOnly = true) public List getTop5UniversitiesEmploymentRates() { - List top5Rates = employmentRateRepository.findTop5ByOrderByUniversityNameAsc(); - return top5Rates.stream() - .map(rate -> new UniversityEmploymentRateResponse( - rate.getUniversity().getName(), - rate.getUniversity().getLogo(), - List.of(convertToDto(rate)) + Map> universityRatesMap = top5Rates.stream() + .collect(Collectors.groupingBy( + EmploymentRate::getUniversity, + Collectors.mapping(this::convertToDto, Collectors.toList()) + )); + return universityRatesMap.entrySet().stream() + .map(entry -> new UniversityEmploymentRateResponse( + entry.getKey().getName(), + entry.getKey().getLogo(), + entry.getValue() + )) + .collect(Collectors.toList()); + } + + @Transactional(readOnly = true) + public List getAllUniversityEmploymentRates() { + List rates = employmentRateRepository.findAll(); + + Map> universityRatesMap = rates.stream() + .collect(Collectors.groupingBy( + EmploymentRate::getUniversity, + Collectors.mapping(this::convertToDto, Collectors.toList()) + )); + return universityRatesMap.entrySet().stream() + .map(entry -> new UniversityEmploymentRateResponse( + entry.getKey().getName(), + entry.getKey().getLogo(), + entry.getValue() )) .collect(Collectors.toList()); } @@ -64,4 +87,16 @@ private EmploymentRateResponse convertToDto(EmploymentRate employmentRate) { employmentRate.getEmploymentRate() ); } + + public List getUniversitiesEmploymentRates() { + + List all = employmentRateRepository.findAll(); + return all.stream().map( + rate -> new UniversityEmploymentRateResponse( + rate.getUniversity().getName(), + rate.getUniversity().getLogo(), + List.of(convertToDto(rate)) + ) + ).collect(Collectors.toList()); + } }