Skip to content

Commit

Permalink
feat: 취업률 반환 형식 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
nyeroni committed Oct 14, 2024
1 parent c5e4d55 commit 5d7f019
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -19,15 +17,15 @@
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/employment-rate")
public class EmploymentRateController {
public class EmploymentRateApiController {

private final EmploymentRateService employmentRateService;
@Operation(
summary = "대학교 취업률 삼년치 조회",
description = "대학교 ID를 이용해 해당 대학교의 취업률 삼년치를 조회합니다."
)
@GetMapping()
public ResponseEntity<UniversityEmploymentRateResponse> getAllEmploymentRates(@RequestParam Long universityId) {
public ResponseEntity<UniversityEmploymentRateResponse> getEmploymentRatesByUniversity(@RequestParam Long universityId) {
UniversityEmploymentRateResponse universityEmploymentRates = employmentRateService.getUniversityEmploymentRates(universityId);
return ResponseEntity.ok(universityEmploymentRates);
}
Expand All @@ -41,4 +39,14 @@ public ResponseEntity<List<UniversityEmploymentRateResponse>> getTop5Universitie
List<UniversityEmploymentRateResponse> top5UniversitiesEmploymentRates = employmentRateService.getTop5UniversitiesEmploymentRates();
return ResponseEntity.ok(top5UniversitiesEmploymentRates);
}

@Operation(
summary = "모든 대학교 취업률 조회",
description = "모든 대학교의 취업률을 조회합니다."
)
@GetMapping("/all")
public ResponseEntity<List<UniversityEmploymentRateResponse>> getAllUniversityEmploymentRates () {
List<UniversityEmploymentRateResponse> UniversitiesEmploymentRates = employmentRateService.getAllUniversityEmploymentRates();
return ResponseEntity.ok(UniversitiesEmploymentRates);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import yerong.wedle.university.repository.UniversityRepository;

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

@Service
Expand Down Expand Up @@ -47,14 +48,36 @@ public UniversityEmploymentRateResponse getUniversityEmploymentRates(Long univer

@Transactional(readOnly = true)
public List<UniversityEmploymentRateResponse> getTop5UniversitiesEmploymentRates() {

List<EmploymentRate> top5Rates = employmentRateRepository.findTop5ByOrderByUniversityNameAsc();

return top5Rates.stream()
.map(rate -> new UniversityEmploymentRateResponse(
rate.getUniversity().getName(),
rate.getUniversity().getLogo(),
List.of(convertToDto(rate))
Map<University, List<EmploymentRateResponse>> 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<UniversityEmploymentRateResponse> getAllUniversityEmploymentRates() {
List<EmploymentRate> rates = employmentRateRepository.findAll();

Map<University, List<EmploymentRateResponse>> 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());
}
Expand All @@ -64,4 +87,16 @@ private EmploymentRateResponse convertToDto(EmploymentRate employmentRate) {
employmentRate.getEmploymentRate()
);
}

public List<UniversityEmploymentRateResponse> getUniversitiesEmploymentRates() {

List<EmploymentRate> all = employmentRateRepository.findAll();
return all.stream().map(
rate -> new UniversityEmploymentRateResponse(
rate.getUniversity().getName(),
rate.getUniversity().getLogo(),
List.of(convertToDto(rate))
)
).collect(Collectors.toList());
}
}

0 comments on commit 5d7f019

Please sign in to comment.