-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from UnivApp/feature/refactor17
Feature/refactor17
- Loading branch information
Showing
26 changed files
with
375 additions
and
149 deletions.
There are no files selected for viewing
30 changes: 0 additions & 30 deletions
30
src/main/java/yerong/wedle/banner/controller/BannerApiController.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
src/main/java/yerong/wedle/banner/exception/BannerNotFoundException.java
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
src/main/java/yerong/wedle/banner/repository/BannerRepository.java
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
src/main/java/yerong/wedle/banner/service/BannerService.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/yerong/wedle/competitionRate/controller/CompetitionRateController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package yerong.wedle.competitionRate.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import yerong.wedle.category.activity.dto.ActivityResponse; | ||
import yerong.wedle.competitionRate.dto.CompetitionRateResponse; | ||
import yerong.wedle.competitionRate.service.CompetitionRateService; | ||
|
||
import java.util.List; | ||
|
||
@Tag(name = "CompetitionRate API", description = "대학교 경쟁률 API") | ||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/competition-rate") | ||
public class CompetitionRateController { | ||
private final CompetitionRateService competitionRateService; | ||
@Operation( | ||
summary = "대학교 경쟁률 삼년치 조회", | ||
description = "대학교 ID를 이용해 해당 대학교의 경쟁률 삼년치를 조회합니다." | ||
) | ||
@GetMapping("/three-years") | ||
public ResponseEntity<List<CompetitionRateResponse>> getAllCompetitionRates(@RequestParam Long universityId) { | ||
List<CompetitionRateResponse> lastThreeYearsCompetitionRates = competitionRateService.getLastThreeYearsCompetitionRates(universityId); | ||
return ResponseEntity.ok(lastThreeYearsCompetitionRates); | ||
} | ||
|
||
@Operation( | ||
summary = "대학교 경쟁률 최근년도 조회", | ||
description = "대학교 ID를 이용해 해당 대학교의 경쟁률 최근년도를 조회합니다." | ||
) | ||
@GetMapping | ||
public ResponseEntity<CompetitionRateResponse> getCompetitionRate(@RequestParam Long universityId) { | ||
CompetitionRateResponse latestCompetitionRate = competitionRateService.getLatestCompetitionRate(universityId); | ||
return ResponseEntity.ok(latestCompetitionRate); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/yerong/wedle/competitionRate/domain/CompetitionRate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package yerong.wedle.competitionRate.domain; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import yerong.wedle.university.domain.University; | ||
|
||
import java.time.LocalDate; | ||
|
||
import static jakarta.persistence.GenerationType.*; | ||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
@NoArgsConstructor(access = PROTECTED) | ||
@Getter | ||
@Entity | ||
public class CompetitionRate { | ||
@Id | ||
@GeneratedValue(strategy = IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "university_id", nullable = false) | ||
private University university; | ||
|
||
private Double earlyAdmissionRate; | ||
private Double regularAdmissionRate; | ||
private String competitionYear; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/yerong/wedle/competitionRate/dto/CompetitionRateResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package yerong.wedle.competitionRate.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class CompetitionRateResponse { | ||
private Double earlyAdmissionRate; | ||
private Double regularAdmissionRate; | ||
private String year; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/yerong/wedle/competitionRate/exception/CompetitionRateNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package yerong.wedle.competitionRate.exception; | ||
|
||
import yerong.wedle.common.exception.CustomException; | ||
import yerong.wedle.common.exception.ResponseCode; | ||
|
||
public class CompetitionRateNotFoundException extends CustomException { | ||
public CompetitionRateNotFoundException() { | ||
super(ResponseCode.COMPETITION_RATE_NOT_FOUND); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/yerong/wedle/competitionRate/repository/CompetitionRateRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package yerong.wedle.competitionRate.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import yerong.wedle.competitionRate.domain.CompetitionRate; | ||
import yerong.wedle.university.domain.University; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface CompetitionRateRepository extends JpaRepository<CompetitionRate, Long> { | ||
List<CompetitionRate> findByUniversity(University university); | ||
|
||
Optional<CompetitionRate> findTopByUniversityOrderByCompetitionYearDesc(University university); | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/yerong/wedle/competitionRate/service/CompetitionRateService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package yerong.wedle.competitionRate.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import yerong.wedle.competitionRate.domain.CompetitionRate; | ||
import yerong.wedle.competitionRate.dto.CompetitionRateResponse; | ||
import yerong.wedle.competitionRate.exception.CompetitionRateNotFoundException; | ||
import yerong.wedle.competitionRate.repository.CompetitionRateRepository; | ||
import yerong.wedle.university.domain.University; | ||
import yerong.wedle.university.exception.UniversityNotFoundException; | ||
import yerong.wedle.university.repository.UniversityRepository; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CompetitionRateService { | ||
|
||
private final CompetitionRateRepository competitionRateRepository; | ||
private final UniversityRepository universityRepository; | ||
@Transactional(readOnly = true) | ||
public List<CompetitionRateResponse> getLastThreeYearsCompetitionRates(Long universityId) { | ||
University university = universityRepository.findById(universityId).orElseThrow(UniversityNotFoundException::new); | ||
List<CompetitionRate> rates = competitionRateRepository.findByUniversity(university); | ||
|
||
return rates.stream() | ||
.map(this::convertToDto) | ||
.collect(Collectors.toList()); | ||
} | ||
@Transactional(readOnly = true) | ||
public CompetitionRateResponse getLatestCompetitionRate(Long universityId) { | ||
University university = universityRepository.findById(universityId).orElseThrow(UniversityNotFoundException::new); | ||
CompetitionRate latestRate = competitionRateRepository.findTopByUniversityOrderByCompetitionYearDesc(university).orElseThrow(CompetitionRateNotFoundException::new); | ||
|
||
return convertToDto(latestRate); | ||
} | ||
private CompetitionRateResponse convertToDto(CompetitionRate competitionRate) { | ||
return new CompetitionRateResponse( | ||
competitionRate.getEarlyAdmissionRate(), | ||
competitionRate.getRegularAdmissionRate(), | ||
competitionRate.getCompetitionYear() | ||
); | ||
} | ||
} |
Oops, something went wrong.