Skip to content

Commit

Permalink
Merge pull request #133 from UnivApp/feature/refactor17
Browse files Browse the repository at this point in the history
Feature/refactor17
  • Loading branch information
nyeroni authored Oct 8, 2024
2 parents 03384fa + 9ba0e6a commit ab4edcc
Show file tree
Hide file tree
Showing 26 changed files with 375 additions and 149 deletions.

This file was deleted.

30 changes: 0 additions & 30 deletions src/main/java/yerong/wedle/banner/domain/Banner.java

This file was deleted.

15 changes: 0 additions & 15 deletions src/main/java/yerong/wedle/banner/dto/BannerResponse.java

This file was deleted.

This file was deleted.

This file was deleted.

40 changes: 0 additions & 40 deletions src/main/java/yerong/wedle/banner/service/BannerService.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ActivityApiController {
description = "대학교 ID를 이용해 해당 대학교의 활동 목록을 조회합니다."
)
@GetMapping
public ResponseEntity<List<ActivityResponse>> getActivitiesByㅜ(@RequestParam Long universityId) {
public ResponseEntity<List<ActivityResponse>> getActivitiesBy(@RequestParam Long universityId) {
List<ActivityResponse> activities = activityService.getActivitiesByUniversityId(universityId);
return ResponseEntity.ok(activities);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/yerong/wedle/category/news/domain/News.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public class News {

@Column(nullable = false)
private LocalDate publishedDate;
private Integer admissionYear;
private String admissionYear;
private String source;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -106,6 +107,25 @@ public ResponseEntity<ErrorResponse> handleAdmissionAnnouncementCategoryNotFound
);
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorResponse);
}

@ExceptionHandler(CompetitionRateNotFoundException.class)
public ResponseEntity<ErrorResponse> 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<ErrorResponse> 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<ErrorResponse> handleNewsNotFoundException(NewsNotFoundException ex) {
ErrorResponse errorResponse = new ErrorResponse(
Expand All @@ -124,15 +144,6 @@ public ResponseEntity<ErrorResponse> handleInvalidAuthorizationHeaderException(I
);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse);
}
@ExceptionHandler(BannerNotFoundException.class)
public ResponseEntity<ErrorResponse> 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<ErrorResponse> handleCalendarEventNotFoundException(CalendarEventNotFoundException ex) {
ErrorResponse errorResponse = new ErrorResponse(
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/yerong/wedle/common/exception/ResponseCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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", "대학 연계 행사 카테고리 정보를 찾을 수 없습니다.");
Expand Down
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);
}
}
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;
}
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;
}
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);
}
}
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);
}
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()
);
}
}
Loading

0 comments on commit ab4edcc

Please sign in to comment.