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 b55cd0c commit c5e4d55
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/competition-rate")
public class CompetitionRateController {
public class CompetitionRateApiController {
private final CompetitionRateService competitionRateService;
@Operation(
summary = "대학교 경쟁률 조회",
description = "대학교 ID를 이용해 해당 대학교의 경쟁률 삼년치를 조회합니다."
)
@GetMapping()
public ResponseEntity<UniversityCompetitionRateResponse> getAllCompetitionRates(@RequestParam Long universityId) {
public ResponseEntity<UniversityCompetitionRateResponse> getAllCompetitionRatesByUniversity(@RequestParam Long universityId) {
UniversityCompetitionRateResponse universityCompetitionRates = competitionRateService.getUniversityCompetitionRates(universityId);
return ResponseEntity.ok(universityCompetitionRates);
}
Expand All @@ -38,4 +38,14 @@ public ResponseEntity<List<UniversityCompetitionRateResponse>> getTop5Universiti
List<UniversityCompetitionRateResponse> top5Rates = competitionRateService.getTop5UniversitiesCompetitionRates();
return ResponseEntity.ok(top5Rates);
}

@Operation(
summary = "모든 대학교 경쟁률 조회",
description = "모든 대학교의 경쟁률을 조회합니다."
)
@GetMapping("/all")
public ResponseEntity<List<UniversityCompetitionRateResponse>> getAllUniversitiesCompetitionRates() {
List<UniversityCompetitionRateResponse> rates = competitionRateService.getAllUniversitiesCompetitionRates();
return ResponseEntity.ok(rates);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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 @@ -45,11 +46,34 @@ public UniversityCompetitionRateResponse getUniversityCompetitionRates(Long univ
public List<UniversityCompetitionRateResponse> getTop5UniversitiesCompetitionRates() {
List<CompetitionRate> top5Rates = competitionRateRepository.findTop5ByOrderByUniversityNameAsc();

return top5Rates.stream()
.map(rate -> new UniversityCompetitionRateResponse(
rate.getUniversity().getName(),
rate.getUniversity().getLogo(),
List.of(convertToDto(rate))
Map<University, List<CompetitionRateResponse>> universityRatesMap = top5Rates.stream()
.collect(Collectors.groupingBy(
CompetitionRate::getUniversity,
Collectors.mapping(this::convertToDto, Collectors.toList())
));
return universityRatesMap.entrySet().stream()
.map(entry -> new UniversityCompetitionRateResponse(
entry.getKey().getName(),
entry.getKey().getLogo(),
entry.getValue()
))
.collect(Collectors.toList());
}

@Transactional(readOnly = true)
public List<UniversityCompetitionRateResponse> getAllUniversitiesCompetitionRates() {

List<CompetitionRate> rates = competitionRateRepository.findAll();
Map<University, List<CompetitionRateResponse>> universityRatesMap = rates.stream()
.collect(Collectors.groupingBy(
CompetitionRate::getUniversity,
Collectors.mapping(this::convertToDto, Collectors.toList())
));
return universityRatesMap.entrySet().stream()
.map(entry -> new UniversityCompetitionRateResponse(
entry.getKey().getName(),
entry.getKey().getLogo(),
entry.getValue()
))
.collect(Collectors.toList());
}
Expand Down

0 comments on commit c5e4d55

Please sign in to comment.