diff --git a/src/main/java/yerong/wedle/banner/controller/BannerApiController.java b/src/main/java/yerong/wedle/banner/controller/BannerApiController.java deleted file mode 100644 index 2f83636..0000000 --- a/src/main/java/yerong/wedle/banner/controller/BannerApiController.java +++ /dev/null @@ -1,30 +0,0 @@ -package yerong.wedle.banner.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.RestController; -import yerong.wedle.banner.dto.BannerResponse; -import yerong.wedle.banner.service.BannerService; - -import java.util.List; - -@Tag(name = "Banner API", description = "배너 정보 API") -@RequiredArgsConstructor -@RestController -@RequestMapping("/api/banners") -public class BannerApiController { - - private final BannerService bannerService; - @Operation( - summary = "배너 조회", description = "모든 배너 목록을 조회합니다." - ) - @GetMapping - public ResponseEntity getBanners() { - List banners = bannerService.getAllBanners(); - return ResponseEntity.ok(banners); - } -} diff --git a/src/main/java/yerong/wedle/banner/domain/Banner.java b/src/main/java/yerong/wedle/banner/domain/Banner.java deleted file mode 100644 index ab5b5ef..0000000 --- a/src/main/java/yerong/wedle/banner/domain/Banner.java +++ /dev/null @@ -1,30 +0,0 @@ -package yerong.wedle.banner.domain; - -import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import yerong.wedle.common.domain.BaseTimeEntity; - -import static jakarta.persistence.GenerationType.IDENTITY; - -@Getter -@NoArgsConstructor -@AllArgsConstructor -@Entity -public class Banner extends BaseTimeEntity { - - @Id - @GeneratedValue(strategy = IDENTITY) - @Column(name = "banner_id") - private Long bannerId; - - @Column(nullable = false) - private String imageUrl; - - @Column(nullable = false) - private String linkUrl; - - private String altText; - -} diff --git a/src/main/java/yerong/wedle/banner/dto/BannerResponse.java b/src/main/java/yerong/wedle/banner/dto/BannerResponse.java deleted file mode 100644 index c7e8fb5..0000000 --- a/src/main/java/yerong/wedle/banner/dto/BannerResponse.java +++ /dev/null @@ -1,15 +0,0 @@ -package yerong.wedle.banner.dto; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@AllArgsConstructor -@NoArgsConstructor -public class BannerResponse { - - private String imageUrl; - private String linkUrl; - private String altText; -} diff --git a/src/main/java/yerong/wedle/banner/exception/BannerNotFoundException.java b/src/main/java/yerong/wedle/banner/exception/BannerNotFoundException.java deleted file mode 100644 index 1c3a99a..0000000 --- a/src/main/java/yerong/wedle/banner/exception/BannerNotFoundException.java +++ /dev/null @@ -1,10 +0,0 @@ -package yerong.wedle.banner.exception; - -import yerong.wedle.common.exception.CustomException; -import yerong.wedle.common.exception.ResponseCode; - -public class BannerNotFoundException extends CustomException { - public BannerNotFoundException() { - super(ResponseCode.BANNER_NOT_FOUND); - } -} diff --git a/src/main/java/yerong/wedle/banner/repository/BannerRepository.java b/src/main/java/yerong/wedle/banner/repository/BannerRepository.java deleted file mode 100644 index 0c638e1..0000000 --- a/src/main/java/yerong/wedle/banner/repository/BannerRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package yerong.wedle.banner.repository; - -import org.springframework.data.jpa.repository.JpaRepository; -import yerong.wedle.banner.domain.Banner; - -public interface BannerRepository extends JpaRepository { -} diff --git a/src/main/java/yerong/wedle/banner/service/BannerService.java b/src/main/java/yerong/wedle/banner/service/BannerService.java deleted file mode 100644 index c8a2a1f..0000000 --- a/src/main/java/yerong/wedle/banner/service/BannerService.java +++ /dev/null @@ -1,40 +0,0 @@ -package yerong.wedle.banner.service; - -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import yerong.wedle.banner.domain.Banner; -import yerong.wedle.banner.dto.BannerResponse; -import yerong.wedle.banner.exception.BannerNotFoundException; -import yerong.wedle.banner.repository.BannerRepository; - -import java.util.List; -import java.util.stream.Collectors; - -@RequiredArgsConstructor -@Service -public class BannerService { - - private final BannerRepository bannerRepository; - - @Transactional(readOnly = true) - public List getAllBanners() { - List banners = bannerRepository.findAll(); - - if (banners.isEmpty()) { - throw new BannerNotFoundException(); - } - - return banners.stream() - .map(this::convertToDto) - .collect(Collectors.toList()); - } - - private BannerResponse convertToDto(Banner banner) { - return new BannerResponse( - banner.getImageUrl(), - banner.getLinkUrl(), - banner.getAltText() - ); - } -} diff --git a/src/main/java/yerong/wedle/category/activity/controller/ActivityApiController.java b/src/main/java/yerong/wedle/category/activity/controller/ActivityApiController.java index aa4871e..058d8e6 100644 --- a/src/main/java/yerong/wedle/category/activity/controller/ActivityApiController.java +++ b/src/main/java/yerong/wedle/category/activity/controller/ActivityApiController.java @@ -25,7 +25,7 @@ public class ActivityApiController { description = "대학교 ID를 이용해 해당 대학교의 활동 목록을 조회합니다." ) @GetMapping - public ResponseEntity> getActivitiesByㅜ(@RequestParam Long universityId) { + public ResponseEntity> getActivitiesBy(@RequestParam Long universityId) { List activities = activityService.getActivitiesByUniversityId(universityId); return ResponseEntity.ok(activities); } diff --git a/src/main/java/yerong/wedle/category/news/domain/News.java b/src/main/java/yerong/wedle/category/news/domain/News.java index b6eb26c..abcd924 100644 --- a/src/main/java/yerong/wedle/category/news/domain/News.java +++ b/src/main/java/yerong/wedle/category/news/domain/News.java @@ -27,6 +27,6 @@ public class News { @Column(nullable = false) private LocalDate publishedDate; - private Integer admissionYear; + private String admissionYear; private String source; } diff --git a/src/main/java/yerong/wedle/category/news/dto/NewsResponse.java b/src/main/java/yerong/wedle/category/news/dto/NewsResponse.java index 7f835ec..89fe1ae 100644 --- a/src/main/java/yerong/wedle/category/news/dto/NewsResponse.java +++ b/src/main/java/yerong/wedle/category/news/dto/NewsResponse.java @@ -15,6 +15,6 @@ public class NewsResponse { private String title; private String link; private LocalDate publishedDate; - private Integer admissionYear; + private String admissionYear; private String source; } diff --git a/src/main/java/yerong/wedle/common/exception/GlobalExceptionHandler.java b/src/main/java/yerong/wedle/common/exception/GlobalExceptionHandler.java index 12e2bd2..163415f 100644 --- a/src/main/java/yerong/wedle/common/exception/GlobalExceptionHandler.java +++ b/src/main/java/yerong/wedle/common/exception/GlobalExceptionHandler.java @@ -4,13 +4,14 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; -import yerong.wedle.banner.exception.BannerNotFoundException; import yerong.wedle.calendar.exception.CalendarEventNotFoundException; import yerong.wedle.category.announcement.exception.AdmissionAnnouncementCategoryNotFoundException; import yerong.wedle.category.announcement.exception.AdmissionAnnouncementNotFoundException; import yerong.wedle.category.news.exception.NewsNotFoundException; import yerong.wedle.category.restaurant.exception.RestaurantNotFoundException; +import yerong.wedle.competitionRate.exception.CompetitionRateNotFoundException; import yerong.wedle.department.exception.DepartmentNotFoundException; +import yerong.wedle.employmentRate.exception.EmploymentRateNotFoundException; import yerong.wedle.member.exception.MemberNotFoundException; import yerong.wedle.member.exception.MemberDuplicateException; import yerong.wedle.oauth.exception.InvalidAuthorizationHeaderException; @@ -106,6 +107,25 @@ public ResponseEntity handleAdmissionAnnouncementCategoryNotFound ); return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorResponse); } + + @ExceptionHandler(CompetitionRateNotFoundException.class) + public ResponseEntity handleCompetitionRateNotFoundException(CompetitionRateNotFoundException ex) { + ErrorResponse errorResponse = new ErrorResponse( + ResponseCode.COMPETITION_RATE_NOT_FOUND.getCode(), + ResponseCode.COMPETITION_RATE_NOT_FOUND.getMessage(), + LocalDateTime.now().format(FORMATTER) + ); + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorResponse); + } + @ExceptionHandler(EmploymentRateNotFoundException.class) + public ResponseEntity handleEmploymentRateNotFoundException(EmploymentRateNotFoundException ex) { + ErrorResponse errorResponse = new ErrorResponse( + ResponseCode.EMPLOYMENT_RATE_NOT_FOUND.getCode(), + ResponseCode.EMPLOYMENT_RATE_NOT_FOUND.getMessage(), + LocalDateTime.now().format(FORMATTER) + ); + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorResponse); + } @ExceptionHandler(NewsNotFoundException.class) public ResponseEntity handleNewsNotFoundException(NewsNotFoundException ex) { ErrorResponse errorResponse = new ErrorResponse( @@ -124,15 +144,6 @@ public ResponseEntity handleInvalidAuthorizationHeaderException(I ); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse); } - @ExceptionHandler(BannerNotFoundException.class) - public ResponseEntity handleBannerNotFoundException(BannerNotFoundException ex) { - ErrorResponse errorResponse = new ErrorResponse( - ResponseCode.BANNER_NOT_FOUND.getCode(), - ResponseCode.BANNER_NOT_FOUND.getMessage(), - LocalDateTime.now().format(FORMATTER) - ); - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorResponse); - } @ExceptionHandler(CalendarEventNotFoundException.class) public ResponseEntity handleCalendarEventNotFoundException(CalendarEventNotFoundException ex) { ErrorResponse errorResponse = new ErrorResponse( diff --git a/src/main/java/yerong/wedle/common/exception/ResponseCode.java b/src/main/java/yerong/wedle/common/exception/ResponseCode.java index 2330771..277d0f4 100644 --- a/src/main/java/yerong/wedle/common/exception/ResponseCode.java +++ b/src/main/java/yerong/wedle/common/exception/ResponseCode.java @@ -44,6 +44,12 @@ public enum ResponseCode { //News NEWS_NOT_FOUND("404", "기사 정보를 찾을 수 없습니다."), + //Competition Rate + COMPETITION_RATE_NOT_FOUND("404", "경쟁률 정보를 찾을 수 없습니다."), + + //Employment Rate + EMPLOYMENT_RATE_NOT_FOUND("404", "취업률 정보를 찾을 수 없습니다."), + //Admission Announcement ADMISSION_ANNOUNCEMENT_NOT_FOUND("404", "대학 연계 행사 정보를 찾을 수 없습니다."), ADMISSION_ANNOUNCEMENT_CATEGORY_NOT_FOUND("404", "대학 연계 행사 카테고리 정보를 찾을 수 없습니다."); diff --git a/src/main/java/yerong/wedle/competitionRate/controller/CompetitionRateController.java b/src/main/java/yerong/wedle/competitionRate/controller/CompetitionRateController.java new file mode 100644 index 0000000..2257581 --- /dev/null +++ b/src/main/java/yerong/wedle/competitionRate/controller/CompetitionRateController.java @@ -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> getAllCompetitionRates(@RequestParam Long universityId) { + List lastThreeYearsCompetitionRates = competitionRateService.getLastThreeYearsCompetitionRates(universityId); + return ResponseEntity.ok(lastThreeYearsCompetitionRates); + } + + @Operation( + summary = "대학교 경쟁률 최근년도 조회", + description = "대학교 ID를 이용해 해당 대학교의 경쟁률 최근년도를 조회합니다." + ) + @GetMapping + public ResponseEntity getCompetitionRate(@RequestParam Long universityId) { + CompetitionRateResponse latestCompetitionRate = competitionRateService.getLatestCompetitionRate(universityId); + return ResponseEntity.ok(latestCompetitionRate); + } +} diff --git a/src/main/java/yerong/wedle/competitionRate/domain/CompetitionRate.java b/src/main/java/yerong/wedle/competitionRate/domain/CompetitionRate.java new file mode 100644 index 0000000..6b78239 --- /dev/null +++ b/src/main/java/yerong/wedle/competitionRate/domain/CompetitionRate.java @@ -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; +} diff --git a/src/main/java/yerong/wedle/competitionRate/dto/CompetitionRateResponse.java b/src/main/java/yerong/wedle/competitionRate/dto/CompetitionRateResponse.java new file mode 100644 index 0000000..392433e --- /dev/null +++ b/src/main/java/yerong/wedle/competitionRate/dto/CompetitionRateResponse.java @@ -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; +} diff --git a/src/main/java/yerong/wedle/competitionRate/exception/CompetitionRateNotFoundException.java b/src/main/java/yerong/wedle/competitionRate/exception/CompetitionRateNotFoundException.java new file mode 100644 index 0000000..cff1f9e --- /dev/null +++ b/src/main/java/yerong/wedle/competitionRate/exception/CompetitionRateNotFoundException.java @@ -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); + } +} diff --git a/src/main/java/yerong/wedle/competitionRate/repository/CompetitionRateRepository.java b/src/main/java/yerong/wedle/competitionRate/repository/CompetitionRateRepository.java new file mode 100644 index 0000000..57b8d95 --- /dev/null +++ b/src/main/java/yerong/wedle/competitionRate/repository/CompetitionRateRepository.java @@ -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 { + List findByUniversity(University university); + + Optional findTopByUniversityOrderByCompetitionYearDesc(University university); +} diff --git a/src/main/java/yerong/wedle/competitionRate/service/CompetitionRateService.java b/src/main/java/yerong/wedle/competitionRate/service/CompetitionRateService.java new file mode 100644 index 0000000..3a144d3 --- /dev/null +++ b/src/main/java/yerong/wedle/competitionRate/service/CompetitionRateService.java @@ -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 getLastThreeYearsCompetitionRates(Long universityId) { + University university = universityRepository.findById(universityId).orElseThrow(UniversityNotFoundException::new); + List 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() + ); + } +} diff --git a/src/main/java/yerong/wedle/department/domain/DepartmentType.java b/src/main/java/yerong/wedle/department/domain/DepartmentType.java index 82a22a2..c0aa3a4 100644 --- a/src/main/java/yerong/wedle/department/domain/DepartmentType.java +++ b/src/main/java/yerong/wedle/department/domain/DepartmentType.java @@ -1,10 +1,13 @@ package yerong.wedle.department.domain; public enum DepartmentType { - NATURAL_SCIENCES("자연계열"), - HUMANITIES("인문계열"), + NATURAL_SCIENCES("자연과학계열"), + HUMANITIES("인문사회계열"), ARTS("예체능계열"), - ENGINEERING("공학계열"); + ENGINEERING("공학계열"), + MEDICAL_SCIENCES("의학계열"); + + private final String displayName; diff --git a/src/main/java/yerong/wedle/employmentRate/controller/EmploymentRateController.java b/src/main/java/yerong/wedle/employmentRate/controller/EmploymentRateController.java new file mode 100644 index 0000000..140f727 --- /dev/null +++ b/src/main/java/yerong/wedle/employmentRate/controller/EmploymentRateController.java @@ -0,0 +1,43 @@ +package yerong.wedle.employmentRate.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.competitionRate.dto.CompetitionRateResponse; +import yerong.wedle.employmentRate.dto.EmploymentRateResponse; +import yerong.wedle.employmentRate.service.EmploymentRateService; + +import java.util.List; + +@Tag(name = "EmploymentRate API", description = "대학교 취업률 API") +@RequiredArgsConstructor +@RestController +@RequestMapping("/api/employment-rate") +public class EmploymentRateController { + + private final EmploymentRateService employmentRateService; + @Operation( + summary = "대학교 취업률 삼년치 조회", + description = "대학교 ID를 이용해 해당 대학교의 취업률 삼년치를 조회합니다." + ) + @GetMapping("/three-years") + public ResponseEntity> getAllEmploymentRates(@RequestParam Long universityId) { + List lastThreeYearsEmploymentRates = employmentRateService.getLastThreeYearsEmploymentRates(universityId); + return ResponseEntity.ok(lastThreeYearsEmploymentRates); + } + + @Operation( + summary = "대학교 취업률 최근년도 조회", + description = "대학교 ID를 이용해 해당 대학교의 취업률 최근년도를 조회합니다." + ) + @GetMapping + public ResponseEntity getEmploymentRate(@RequestParam Long universityId) { + EmploymentRateResponse latestEmploymentRate = employmentRateService.getLatestEmploymentRate(universityId); + return ResponseEntity.ok(latestEmploymentRate); + } +} diff --git a/src/main/java/yerong/wedle/employmentRate/domain/EmploymentRate.java b/src/main/java/yerong/wedle/employmentRate/domain/EmploymentRate.java new file mode 100644 index 0000000..b745c06 --- /dev/null +++ b/src/main/java/yerong/wedle/employmentRate/domain/EmploymentRate.java @@ -0,0 +1,25 @@ +package yerong.wedle.employmentRate.domain; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.NoArgsConstructor; +import yerong.wedle.university.domain.University; + +import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; + +@NoArgsConstructor(access = PROTECTED) +@Getter +@Entity +public class EmploymentRate { + @Id + @GeneratedValue(strategy = IDENTITY) + private Long id; + + @ManyToOne + @JoinColumn(name = "university_id", nullable = false) + private University university; + + private Double employmentRate; + private String employmentYear; +} diff --git a/src/main/java/yerong/wedle/employmentRate/dto/EmploymentRateResponse.java b/src/main/java/yerong/wedle/employmentRate/dto/EmploymentRateResponse.java new file mode 100644 index 0000000..876b337 --- /dev/null +++ b/src/main/java/yerong/wedle/employmentRate/dto/EmploymentRateResponse.java @@ -0,0 +1,13 @@ +package yerong.wedle.employmentRate.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class EmploymentRateResponse { + private Double employmentRate; + private String year; +} diff --git a/src/main/java/yerong/wedle/employmentRate/exception/EmploymentRateNotFoundException.java b/src/main/java/yerong/wedle/employmentRate/exception/EmploymentRateNotFoundException.java new file mode 100644 index 0000000..46a2294 --- /dev/null +++ b/src/main/java/yerong/wedle/employmentRate/exception/EmploymentRateNotFoundException.java @@ -0,0 +1,10 @@ +package yerong.wedle.employmentRate.exception; + +import yerong.wedle.common.exception.CustomException; +import yerong.wedle.common.exception.ResponseCode; + +public class EmploymentRateNotFoundException extends CustomException { + public EmploymentRateNotFoundException() { + super(ResponseCode.EMPLOYMENT_RATE_NOT_FOUND); + } +} diff --git a/src/main/java/yerong/wedle/employmentRate/repository/EmploymentRateRepository.java b/src/main/java/yerong/wedle/employmentRate/repository/EmploymentRateRepository.java new file mode 100644 index 0000000..29e27c6 --- /dev/null +++ b/src/main/java/yerong/wedle/employmentRate/repository/EmploymentRateRepository.java @@ -0,0 +1,15 @@ +package yerong.wedle.employmentRate.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import yerong.wedle.competitionRate.domain.CompetitionRate; +import yerong.wedle.employmentRate.domain.EmploymentRate; +import yerong.wedle.university.domain.University; + +import java.util.List; +import java.util.Optional; + +public interface EmploymentRateRepository extends JpaRepository { + List findByUniversity(University university); + + Optional findTopByUniversityOrderByEmploymentYearDesc(University university); +} diff --git a/src/main/java/yerong/wedle/employmentRate/service/EmploymentRateService.java b/src/main/java/yerong/wedle/employmentRate/service/EmploymentRateService.java new file mode 100644 index 0000000..acfe463 --- /dev/null +++ b/src/main/java/yerong/wedle/employmentRate/service/EmploymentRateService.java @@ -0,0 +1,48 @@ +package yerong.wedle.employmentRate.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.employmentRate.domain.EmploymentRate; +import yerong.wedle.employmentRate.dto.EmploymentRateResponse; +import yerong.wedle.employmentRate.exception.EmploymentRateNotFoundException; +import yerong.wedle.employmentRate.repository.EmploymentRateRepository; +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 EmploymentRateService { + + private final EmploymentRateRepository employmentRateRepository; + private final UniversityRepository universityRepository; + @Transactional(readOnly = true) + public List getLastThreeYearsEmploymentRates(Long universityId) { + University university = universityRepository.findById(universityId).orElseThrow(UniversityNotFoundException::new); + List rates = employmentRateRepository.findByUniversity(university); + + return rates.stream() + .map(this::convertToDto) + .collect(Collectors.toList()); + } + @Transactional(readOnly = true) + public EmploymentRateResponse getLatestEmploymentRate(Long universityId) { + University university = universityRepository.findById(universityId).orElseThrow(UniversityNotFoundException::new); + EmploymentRate latestRate = employmentRateRepository.findTopByUniversityOrderByEmploymentYearDesc(university).orElseThrow(EmploymentRateNotFoundException::new); + + return convertToDto(latestRate); + } + private EmploymentRateResponse convertToDto(EmploymentRate employmentRate) { + return new EmploymentRateResponse( + employmentRate.getEmploymentRate(), + employmentRate.getEmploymentYear() + ); + } +} diff --git a/src/main/java/yerong/wedle/university/dto/UniversityAllResponse.java b/src/main/java/yerong/wedle/university/dto/UniversityAllResponse.java index 38b6512..7422542 100644 --- a/src/main/java/yerong/wedle/university/dto/UniversityAllResponse.java +++ b/src/main/java/yerong/wedle/university/dto/UniversityAllResponse.java @@ -3,6 +3,10 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; +import yerong.wedle.competitionRate.dto.CompetitionRateResponse; +import yerong.wedle.employmentRate.dto.EmploymentRateResponse; + +import java.util.List; @AllArgsConstructor @NoArgsConstructor @@ -17,4 +21,7 @@ public class UniversityAllResponse { private String website; private String admissionSite; private Long starNum; + private List competitionRateResponses; + private List employmentRateResponses; + } diff --git a/src/main/java/yerong/wedle/university/service/UniversityService.java b/src/main/java/yerong/wedle/university/service/UniversityService.java index 48b53f7..e435234 100644 --- a/src/main/java/yerong/wedle/university/service/UniversityService.java +++ b/src/main/java/yerong/wedle/university/service/UniversityService.java @@ -4,6 +4,13 @@ import org.springframework.security.core.context.SecurityContextHolder; 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.repository.CompetitionRateRepository; +import yerong.wedle.employmentRate.domain.EmploymentRate; +import yerong.wedle.employmentRate.dto.EmploymentRateResponse; +import yerong.wedle.employmentRate.repository.EmploymentRateRepository; +import yerong.wedle.employmentRate.service.EmploymentRateService; import yerong.wedle.member.domain.Member; import yerong.wedle.member.exception.MemberNotFoundException; import yerong.wedle.member.repository.MemberRepository; @@ -24,6 +31,9 @@ public class UniversityService { private final UniversityRepository universityRepository; private final StarRepository starRepository; private final MemberRepository memberRepository; + private final EmploymentRateRepository employmentRateRepository; + private final CompetitionRateRepository competitionRateRepository; + @Transactional public List searchUniversitiesSummary(String keyward) { List universities = universityRepository.findByNameContainingOrLocationContaining(keyward, keyward); @@ -82,6 +92,17 @@ private UniversityResponse convertToSummaryDto(University university) { private UniversityAllResponse convertToDetailDto(University university) { Long starNum = starRepository.countByUniversityId(university.getUniversityId()); // 관심 설정된 횟수 계산 + List competitionRates = competitionRateRepository.findByUniversity(university); + List employmentRates = employmentRateRepository.findByUniversity(university); // EmploymentRate 데이터를 가져옵니다. + + List competitionRateResponses = competitionRates.stream() + .map(rate -> new CompetitionRateResponse(rate.getEarlyAdmissionRate(), rate.getRegularAdmissionRate(), rate.getCompetitionYear())) + .collect(Collectors.toList()); + + List employmentRateResponses = employmentRates.stream() + .map(rate -> new EmploymentRateResponse(rate.getEmploymentRate(), rate.getEmploymentYear())) + .collect(Collectors.toList()); + return new UniversityAllResponse( university.getUniversityId(), university.getName(), @@ -91,7 +112,9 @@ private UniversityAllResponse convertToDetailDto(University university) { university.getPhoneNumber(), university.getWebsite(), university.getAdmissionSite(), - starNum + starNum, + competitionRateResponses, + employmentRateResponses ); } private String getCurrentUserId() {