-
Notifications
You must be signed in to change notification settings - Fork 309
Step3 리뷰요청 드립니다. #824
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
Merged
Merged
Step3 리뷰요청 드립니다. #824
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b939e50
feat: session, enrollment 테이블 생성
qwer920414-ctrl e10c3f7
feat: session, enrollment 테이블 수정(type -> name)
qwer920414-ctrl a7517a6
feat: SessionRepository 생성
qwer920414-ctrl c4d0b06
feat: JdbcSessionRepository 구현
qwer920414-ctrl ae4c83f
feat: Session 클래스 toString() 추가
qwer920414-ctrl 6745df7
feat: EnrollmentRepository 생성
qwer920414-ctrl 8a0e625
style: 패키지 정리
qwer920414-ctrl b4b1f5b
feat: SessionService
qwer920414-ctrl df99e8a
refactor: EnrollmentPolicyFactory 생성
qwer920414-ctrl 89184d9
refactor: Enrollment의 add() 메소드명 수정
qwer920414-ctrl 836d0d5
refactor: 패키지 구조 수정
qwer920414-ctrl 59aa2e3
feat: Session 클래스에 courseId 추가
qwer920414-ctrl 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 hidden or 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
36 changes: 36 additions & 0 deletions
36
src/main/java/nextstep/courses/domain/enrollment/Enrollment.java
This file contains hidden or 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,36 @@ | ||
| package nextstep.courses.domain.enrollment; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public class Enrollment { | ||
| private final Long sessionId; | ||
| private final Long userId; | ||
| private final LocalDateTime enrollmentDate; | ||
|
|
||
| public Enrollment(Long sessionId, Long userId) { | ||
| this(sessionId, userId, LocalDateTime.now()); | ||
| } | ||
|
|
||
| public Enrollment(Long sessionId, Long userId, LocalDateTime enrollmentDate) { | ||
| this.sessionId = sessionId; | ||
| this.userId = userId; | ||
| this.enrollmentDate = enrollmentDate; | ||
| } | ||
|
|
||
| public boolean isSameUser(Long userId) { | ||
| return this.userId.equals(userId); | ||
| } | ||
|
|
||
| public Long getSessionId() { | ||
| return sessionId; | ||
| } | ||
|
|
||
|
|
||
| public Long getUserId() { | ||
| return userId; | ||
| } | ||
|
|
||
| public LocalDateTime getEnrollmentDate() { | ||
| return enrollmentDate; | ||
| } | ||
| } |
4 changes: 3 additions & 1 deletion
4
...step/courses/domain/EnrollmentPolicy.java → ...s/domain/enrollment/EnrollmentPolicy.java
This file contains hidden or 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,9 @@ | ||
| package nextstep.courses.domain; | ||
| package nextstep.courses.domain.enrollment; | ||
|
|
||
| import nextstep.payments.domain.Payment; | ||
|
|
||
| public interface EnrollmentPolicy { | ||
| PolicyType type(); | ||
| Long price(); | ||
| void validateEnrollment(Payment payment); | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/main/java/nextstep/courses/domain/enrollment/EnrollmentPolicyFactory.java
This file contains hidden or 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,20 @@ | ||
| package nextstep.courses.domain.enrollment; | ||
|
|
||
| import static nextstep.courses.domain.enrollment.PolicyType.FREE; | ||
| import static nextstep.courses.domain.enrollment.PolicyType.PAID; | ||
|
|
||
| public class EnrollmentPolicyFactory { | ||
| public static EnrollmentPolicy create(String name, Long price) { | ||
| PolicyType type = PolicyType.valueOf(name); | ||
|
|
||
| if (type == FREE) { | ||
| return new FreeEnrollmentPolicy(); | ||
| } | ||
|
|
||
| if (type == PAID) { | ||
| return new PaidEnrollmentPolicy(new Money(price)); | ||
| } | ||
|
|
||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
This file contains hidden or 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
12 changes: 11 additions & 1 deletion
12
.../courses/domain/FreeEnrollmentPolicy.java → ...main/enrollment/FreeEnrollmentPolicy.java
This file contains hidden or 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 hidden or 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 hidden or 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
6 changes: 6 additions & 0 deletions
6
src/main/java/nextstep/courses/domain/enrollment/PolicyType.java
This file contains hidden or 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,6 @@ | ||
| package nextstep.courses.domain.enrollment; | ||
|
|
||
| public enum PolicyType { | ||
| FREE, | ||
| PAID | ||
| } |
112 changes: 112 additions & 0 deletions
112
src/main/java/nextstep/courses/domain/session/Session.java
This file contains hidden or 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,112 @@ | ||
| package nextstep.courses.domain.session; | ||
|
|
||
| import nextstep.courses.domain.enrollment.Enrollment; | ||
| import nextstep.courses.domain.enrollment.EnrollmentPolicy; | ||
| import nextstep.courses.domain.enrollment.Enrollments; | ||
| import nextstep.courses.domain.session.cover.CoverImage; | ||
| import nextstep.payments.domain.Payment; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public class Session { | ||
| private final long id; | ||
| private final long courseId; | ||
| private final SessionDuration sessionDuration; | ||
| private final CoverImage coverImage; | ||
| private final EnrollmentPolicy enrollmentPolicy; | ||
| private final SessionState sessionState; | ||
| private final Enrollments enrollments; | ||
|
|
||
| public Session(long id | ||
| , long courseId | ||
| , LocalDateTime startDate | ||
| , LocalDateTime endDate | ||
| , int size | ||
| , String fileName | ||
| , int width | ||
| , int height | ||
| , EnrollmentPolicy enrollmentPolicy | ||
| , SessionState sessionState | ||
| , Enrollments enrollments) { | ||
|
|
||
| this(id, courseId, new SessionDuration(startDate, endDate), new CoverImage(size, fileName, width, height) | ||
| , enrollmentPolicy, sessionState, enrollments); | ||
| } | ||
|
|
||
| public Session(long id, long courseId, SessionDuration sessionDuration, CoverImage coverImage | ||
| , EnrollmentPolicy enrollmentPolicy, SessionState sessionState, Enrollments enrollments) { | ||
| this.id = id; | ||
| this.courseId = courseId; | ||
| this.sessionDuration = sessionDuration; | ||
| this.coverImage = coverImage; | ||
| this.enrollmentPolicy = enrollmentPolicy; | ||
| this.sessionState = sessionState; | ||
| this.enrollments = enrollments; | ||
| } | ||
|
|
||
| public Enrollment enroll(Long userId, Payment payment) { | ||
| sessionState.validateEnroll(); | ||
| enrollmentPolicy.validateEnrollment(payment); | ||
| return enrollments.enroll(this.id, userId); | ||
| } | ||
|
|
||
| public long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public long getCourseId() { | ||
| return courseId; | ||
| } | ||
|
|
||
| public LocalDateTime getStartDate() { | ||
| return sessionDuration.getStartDate(); | ||
| } | ||
|
|
||
| public LocalDateTime getEndDate() { | ||
| return sessionDuration.getEndDate(); | ||
| } | ||
|
|
||
| public int getCoverImageSize() { | ||
| return coverImage.getImageSize(); | ||
| } | ||
|
|
||
| public String getCoverImageName() { | ||
| return coverImage.getImageName(); | ||
| } | ||
|
|
||
| public int getCoverImageWidth() { | ||
| return coverImage.getCoverImageWidth(); | ||
| } | ||
|
|
||
| public int getCoverImageHeight() { | ||
| return coverImage.getCoverImageHeight(); | ||
| } | ||
|
|
||
| public String getPolicyType() { | ||
| return enrollmentPolicy.type().name(); | ||
| } | ||
|
|
||
| public long getPrice() { | ||
| return enrollmentPolicy.price(); | ||
| } | ||
|
|
||
| public String getState() { | ||
| return sessionState.name(); | ||
| } | ||
|
|
||
| public int getCapacity() { | ||
| return enrollments.getCapacity(); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Session{" + | ||
| "id=" + id + | ||
| ", sessionDuration=" + sessionDuration + | ||
| ", coverImage=" + coverImage + | ||
| ", enrollmentPolicy=" + enrollmentPolicy + | ||
| ", sessionState=" + sessionState + | ||
| ", enrollments=" + enrollments + | ||
| '}'; | ||
| } | ||
| } |
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.
EnrollmentPolicy 생성을 PolicyType이 담당하기 보다 별도의 EnrollmentPolicyFactory와 같은 객체를 추가하는 것은 어떨까?