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

도서 대출 연장 기능 추가 및 테스트 #14

Merged
merged 11 commits into from
Jan 31, 2025
2 changes: 1 addition & 1 deletion src/main/java/com/study/bookcafe/domain/borrow/Borrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private void increaseExtendCount() {
public void extend() {
if (!canExtend()) return;

Period extendedPeriod = this.getPeriod().createExtended(this.getMember().getLevel());
Period extendedPeriod = this.getPeriod().extend(this.getMember().getLevel());

extendPeriod(extendedPeriod);
increaseExtendCount();
Expand Down
34 changes: 8 additions & 26 deletions src/main/java/com/study/bookcafe/domain/borrow/Period.java
Original file line number Diff line number Diff line change
@@ -1,48 +1,30 @@
package com.study.bookcafe.domain.borrow;

import com.study.bookcafe.domain.member.Level;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import java.time.LocalDate;

@EqualsAndHashCode
public class Period {
/*
- 대출 일자가 반납 일자보다 더 이전인 것을 보장할 책임
- 대출 기간(대출 일자 ~ 반납 일자)을 생성할 책임
- 연장 여부에 따라 반납 일자가 변경
- 기본: 1주, 연장 시: 1주 추가, 총 2주
*/

private final LocalDate from; // 대출 일자
private final LocalDate to; // 반납 일자

private Period(@NonNull LocalDate from, Level level) {
this.from = from;
this.to = this.from.plusWeeks(level.getBorrowPeriod());
}
private final LocalDate from; // 시작 일자
private final LocalDate to; // 종료 일자

public Period(@NonNull LocalDate from, @NonNull LocalDate to) {
if(from.isAfter(to)) throw new IllegalArgumentException("반납 일자는 대출 일자보다 이후여야 합니다.");
if(from.isAfter(to)) throw new IllegalArgumentException("시작 일자는 종료 일자보다 이후여야 합니다.");

this.from = from;
this.to = to;
}

public static Period of(@NonNull LocalDate from, Level level) {
return new Period(from, level);
public Period extendByWeeks(int addWeeks) {
return new Period(from, to.plusWeeks(addWeeks));
}

public Period createExtended(Level level) {
return new Period(from, to.plusWeeks(level.getExtendPeriod()));
}

public boolean isExtendable() {
public LocalDate getMidDate() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 메서드가 범용적인 Period에 어울리는지는 저도 조금 애매하다고 생각하지만 BorrowPeriod 와의 협력에서 중간 날짜를 가지는 메세지가 필요해서 작성했습니다.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

근데 무슨 메서드에요? 어떤.. 기능?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 커밋대상이 잘못 됐습니다

long epochDay = (from.toEpochDay() + to.toEpochDay()) / 2;
LocalDate targetDate = LocalDate.ofEpochDay(epochDay).minusDays(1);
LocalDate now = LocalDate.now();

return now.isAfter(targetDate);
return LocalDate.ofEpochDay(epochDay);
}


}
Loading