Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 다음 상환평가일 기능에 차수 추가 #46

Merged
merged 3 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public ResponsePage<SummarizedProductDto> searchProduct(@Valid @RequestBody Requ
* 특정 상품의 다음 상환평가일 조회
* <p>
* 조기상환평가일이 모두 지나면, 가장 마지막은 만기상환평가일을 보여줍니다.
* 반환 값에 order는 몇 번째 상환평가일에 해당하는지의 차수를 의미합니다.
* </p>
*
* @param id 상품 id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
@Getter
public class ResponseNextRepaymentEvaluationDateDto {

@Schema(description = "차수", example = "2")
private final int order;

@Schema(description = "다음 상환평가일", example = "2027-01-13")
private final LocalDate nextRepaymentEvaluationDate;

public ResponseNextRepaymentEvaluationDateDto(LocalDate nextRepaymentEvaluationDate) {
public ResponseNextRepaymentEvaluationDateDto(int order,
LocalDate nextRepaymentEvaluationDate) {
this.order = order;
this.nextRepaymentEvaluationDate = nextRepaymentEvaluationDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@

public interface EarlyRepaymentEvaluationDatesRepository extends JpaRepository<EarlyRepaymentEvaluationDates, Long> {

@Query("select count(e) + 1 from EarlyRepaymentEvaluationDates e " +
"where e.product.id = :productId " +
"and e.earlyRepaymentEvaluationDate < :targetDate ")
Optional<Integer> findNextEarlyRepaymentEvaluationDateOrder(@RequestParam("productId") Long productId,
@RequestParam("targetDate") LocalDate targetDate);

@Query("select e.earlyRepaymentEvaluationDate from EarlyRepaymentEvaluationDates e " +
"where e.product.productState = 'ACTIVE' " +
"and e.product.id = :productId " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@ public ResponseNextRepaymentEvaluationDateDto findNextRepaymentEvaluationDate(Lo
throw new ProductEarlyRepaymentEvaluationDateFoundException();
}

int order;
LocalDate nextDate;
if (earlyRepaymentEvaluationDatesRepository.findNextEarlyRepaymentEvaluationDate(productId).isEmpty()) {
// 자동 조기 상환일이 다 끝났다면, 마지막 만기 상환 평가일을 보여주도록함
nextDate = productRepository.findOne(productId).orElseThrow(ProductNotFoundException::new).getMaturityEvaluationDate();
if (nextDate == null) {
throw new ProductMaturityEvaluationDateNotFoundException();
}
order = earlyRepaymentEvaluationDatesList.size() + 1;

} else {
nextDate = earlyRepaymentEvaluationDatesRepository.findNextEarlyRepaymentEvaluationDate(productId).get();
order = earlyRepaymentEvaluationDatesRepository.findNextEarlyRepaymentEvaluationDateOrder(productId, nextDate).get();
}
return new ResponseNextRepaymentEvaluationDateDto(nextDate);
return new ResponseNextRepaymentEvaluationDateDto(order, nextDate);
}

public ResponseMaturityRepaymentEvaluationDateDto findMaturityRepaymentEvaluationDate(Long productId) {
Expand Down