-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3221555
도서 대출 연장 기능 추가 및 테스트
shine-17 7a89eb5
연장 가능여부 확인 로직 변경
shine-17 23ec6b3
연장한 대출의 반납 일자 변경하는 책임을 Period로 변경
shine-17 886f768
- 연장 가능한 날짜인지 여부의 책임을 Period에 할당
shine-17 8a5658f
연장 가능한 날짜인지 판단하는 로직 변경
shine-17 fc84d63
예약이 있는지 판단하는 로직 변경
shine-17 559eeb4
Inventory 테스트셋 추가
shine-17 43abbc2
기간과 대출 기간의 도메인 분리
shine-17 0c0ee5e
기간과 대출 기간의 도메인 분리
shine-17 c9979b3
도메인 객체 Period -> BorrowPeriod 변경으로 인한 수정
shine-17 a472be3
메서드명 수정
shine-17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
34 changes: 8 additions & 26 deletions
34
src/main/java/com/study/bookcafe/domain/borrow/Period.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 |
---|---|---|
@@ -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() { | ||
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); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 메서드가 범용적인 Period에 어울리는지는 저도 조금 애매하다고 생각하지만
BorrowPeriod
와의 협력에서 중간 날짜를 가지는 메세지가 필요해서 작성했습니다.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
근데 무슨 메서드에요? 어떤.. 기능?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앗 커밋대상이 잘못 됐습니다