-
Notifications
You must be signed in to change notification settings - Fork 247
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
Step3 #384
Open
henry174
wants to merge
10
commits into
next-step:henry174
Choose a base branch
from
henry174:step3
base: henry174
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Step3 #384
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
54ab1b1
refactor: InfinitablePositiveInteger의 이름을 MaxRegister로 변경
7fbc3e7
refactor: 선택지가 하나밖에 없는 enum LengthUnit 제거
cdce9b0
refactor: 선택지가 하나밖에 없는 enum CapacityUnit 제거
1c37f84
refactor: 비교문 단순화
0912084
test: capacity 테스트 추가
276ad9f
test: MaxRegister 테스트 추가
eaae6cc
feature: 도메인 객체 Session을 테이블 매핑함.
90a70b9
feature: save시 pk를 반환하도록 수정
f60719a
refactor: JdbcSessionRepository에서 create 메서드로 Session 생성
90cdc8a
feature: Session을 저장할 때 등록된 유저도 같이 저장되고 불러올 때 같이 불러와 짐.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,4 +61,8 @@ public String toString() { | |
", updatedAt=" + updatedAt + | ||
'}'; | ||
} | ||
|
||
public Long getId() { | ||
return this.id; | ||
} | ||
} |
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,7 +1,7 @@ | ||
package nextstep.courses.domain; | ||
|
||
public interface CourseRepository { | ||
int save(Course course); | ||
long save(Course course); | ||
|
||
Course findById(Long id); | ||
} |
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
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,6 +1,6 @@ | ||
package nextstep.courses.domain; | ||
|
||
import nextstep.courses.type.InfinitablePositiveInteger; | ||
import nextstep.courses.type.MaxRegister; | ||
import nextstep.courses.type.SessionDuration; | ||
import nextstep.courses.type.SessionState; | ||
import nextstep.payments.domain.Payment; | ||
|
@@ -24,48 +24,49 @@ public class Session { | |
private SessionImage coverImage; | ||
private SessionDuration duration; | ||
|
||
private InfinitablePositiveInteger maxUserCount; | ||
private MaxRegister maxUserCount; | ||
private int fee; | ||
|
||
|
||
private Session() { | ||
|
||
} | ||
|
||
public static Session createFreeSession(Long id, Course course, SessionImage coverImage, SessionDuration duration) { | ||
public static Session create(Long id, Course course, SessionState state, RegisteredUsers registeredUsers, SessionImage coverImage, SessionDuration duration, MaxRegister maxUserCount, int fee) { | ||
Session session = new Session(); | ||
|
||
session.id = id; | ||
session.course = course; | ||
session.state = READY; | ||
session.registeredUsers = new RegisteredUsers(); | ||
session.state = state; | ||
session.registeredUsers = registeredUsers; | ||
session.coverImage = coverImage; | ||
session.duration = duration; | ||
session.maxUserCount = InfinitablePositiveInteger.infinite(); | ||
session.fee = 0; | ||
session.maxUserCount = maxUserCount; | ||
session.fee = fee; | ||
|
||
validateSession(session); | ||
return session; | ||
} | ||
|
||
public static Session createPaidSession(Long id, Course course, SessionImage coverImage, SessionDuration duration, InfinitablePositiveInteger maxUserCount, int fee) { | ||
Session session = new Session(); | ||
|
||
session.id = id; | ||
session.course = course; | ||
session.state = READY; | ||
session.registeredUsers = new RegisteredUsers(); | ||
session.coverImage = coverImage; | ||
session.duration = duration; | ||
session.maxUserCount = maxUserCount; | ||
session.fee = fee; | ||
public static Session createFreeSession(Long id, Course course, SessionImage coverImage, SessionDuration duration) { | ||
return Session.create(id, course, READY, new RegisteredUsers(), coverImage, duration, MaxRegister.infinite(), 0); | ||
} | ||
|
||
validateSession(session); | ||
return session; | ||
public static Session createPaidSession(Long id, Course course, SessionImage coverImage, SessionDuration duration, MaxRegister maxUserCount, int fee) { | ||
return Session.create(id, course, READY, new RegisteredUsers(), coverImage, duration, maxUserCount, fee); | ||
} | ||
|
||
private static void validateSession(Session session) { | ||
validateFee(session.fee); | ||
validateMaxUserCount(session.maxUserCount, session.fee); | ||
} | ||
|
||
private static void validateMaxUserCount(MaxRegister maxUserCount, int fee) { | ||
if (fee == 0 && maxUserCount.isFinite()) { | ||
throw new IllegalArgumentException("무료 강의는 수강 제한 인원을 둘 수 없습니다."); | ||
} | ||
} | ||
|
||
private static void validateFee(int fee) { | ||
if (fee < 0) { | ||
throw new IllegalArgumentException("강의료가 음수일 수 없습니다."); | ||
|
@@ -88,15 +89,15 @@ public void registerUser(NsUser user) { | |
} | ||
|
||
public void registerUser(NsUser user, Payment payment) { | ||
if (payment.isSameUser(user) == false) { | ||
if (!payment.isSameUser(user)) { | ||
throw new IllegalArgumentException("지불 정보와 등록하는 유저가 일치하지 않습니다."); | ||
} | ||
|
||
if (payment.isSameAmountWith(this.fee) == false) { | ||
if (!payment.isSameAmountWith(this.fee)) { | ||
throw new IllegalArgumentException("수강료와 지불 금액이 동일하지 않습니다."); | ||
} | ||
|
||
if (this.maxUserCount.isLargerThan(this.registeredUsers.theNumberOfUsers()) == false) { | ||
if (!this.maxUserCount.isLargerThan(this.registeredUsers.theNumberOfUsers())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enrollment와 같은 객체를 추가해 maxUserCount와 수강생 목록을 가지고 수강 신청 가능 여부를 Enrollment가 담당하도록 구현하는 것은 어떨까? |
||
throw new IllegalStateException("이 강의의 최대 등록 가능 인원에 도달했습니다. 더 이상 사용자를 추가할 수 없습니다."); | ||
} | ||
|
||
|
@@ -116,6 +117,31 @@ public Long getId() { | |
return this.id; | ||
} | ||
|
||
|
||
public Course getCourse() { | ||
return course; | ||
} | ||
|
||
public SessionState getState() { | ||
return state; | ||
} | ||
|
||
public SessionImage getCoverImage() { | ||
return coverImage; | ||
} | ||
|
||
public SessionDuration getDuration() { | ||
return duration; | ||
} | ||
|
||
public MaxRegister getMaxUserCount() { | ||
return maxUserCount; | ||
} | ||
|
||
public int getFee() { | ||
return fee; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
|
@@ -141,4 +167,8 @@ public String toString() { | |
", fee=" + fee + | ||
'}'; | ||
} | ||
|
||
public RegisteredUsers getRegisteredUsers() { | ||
return this.registeredUsers; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,11 +3,13 @@ | |
import nextstep.courses.type.*; | ||
|
||
public class SessionImage { | ||
private static final Capacity MAX_CAPACITY = new Capacity(1024, CapacityUnit.KB); | ||
private static final Rectangle MIN_SIZE = new Rectangle(300, 200, LengthUnit.PIXEL); | ||
private static final Capacity MAX_CAPACITY = new Capacity(1024); | ||
private static final Rectangle MIN_SIZE = new Rectangle(300, 200); | ||
private static final int WIDTH_RATIO = 3; | ||
private static final int HEIGHT_RATIO = 2; | ||
|
||
private String filePath; | ||
|
||
/** | ||
* 이미지 용량 | ||
*/ | ||
|
@@ -18,22 +20,32 @@ public class SessionImage { | |
*/ | ||
private Rectangle size; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
|
||
private ImageExtension type; | ||
|
||
public SessionImage(Capacity capacity, Rectangle size, ImageExtension type) { | ||
public SessionImage(String filePath, Capacity capacity, Rectangle size, ImageExtension type) { | ||
validateCapacity(capacity); | ||
validateSize(size); | ||
|
||
this.filePath = filePath; | ||
this.capacity = capacity; | ||
this.size = size; | ||
this.type = type; | ||
} | ||
|
||
public SessionImage(String filePath, int capacity, int width, int height, ImageExtension type) { | ||
this( | ||
filePath, | ||
new Capacity(capacity), | ||
new Rectangle(width, height), | ||
type | ||
); | ||
} | ||
|
||
public SessionImage(int capacity, int width, int height, ImageExtension type) { | ||
this( | ||
new Capacity(capacity, CapacityUnit.KB), | ||
new Rectangle(width, height, LengthUnit.PIXEL), | ||
"", | ||
new Capacity(capacity), | ||
new Rectangle(width, height), | ||
type | ||
); | ||
} | ||
|
@@ -47,4 +59,19 @@ private static void validateSize(Rectangle size) { | |
size.throwIfRatioIsNotTheSameWith(WIDTH_RATIO, HEIGHT_RATIO); | ||
} | ||
|
||
} | ||
public String getFilePath() { | ||
return filePath; | ||
} | ||
|
||
public Capacity getCapacity() { | ||
return capacity; | ||
} | ||
|
||
public Rectangle getSize() { | ||
return size; | ||
} | ||
|
||
public ImageExtension getType() { | ||
return type; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package nextstep.courses.domain; | ||
|
||
public interface SessionRepository { | ||
long save(Session session); | ||
|
||
Session findById(Long id); | ||
} |
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
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.
DB에 매핑을 하다보면 Session과 NsUser가 m:n 관계를 가지게 된다.
즉 sessionId와 nsUserId를 가지는 매핑 테이블이 필요하고, 이 매핑 정보를 담고 있는 Student와 객체로 바뀌지 않을까?