-
Notifications
You must be signed in to change notification settings - Fork 309
Step3 - 수강신청(DB 적용) #823
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 - 수강신청(DB 적용) #823
Changes from all commits
5eecd36
e256a38
51800b1
1a05df3
e617a46
55b9cda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.Objects; | ||
|
|
||
| public class Session { | ||
|
Contributor
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. Service Layer를 담당하는 Service 클래스도 추가해 보는 것은 어떨까? |
||
| private final Long id; | ||
| private final ImageFile imageFile; | ||
|
|
@@ -8,8 +11,16 @@ public class Session { | |
| private final EnrollmentRule enrollmentRule; | ||
| private final Enrollments enrollments; | ||
|
|
||
| public Session(Long id, ImageFile imageFile, SessionPeriod period, SessionStatus sessionStatus, EnrollmentRule enrollmentRule) { | ||
| this(id, imageFile, period, sessionStatus, enrollmentRule, new Enrollments()); | ||
| public Session(Long id,ImageFile imageFile, LocalDateTime startTime, LocalDateTime endTime, String sessionStatus, Integer price, Integer capacity) { | ||
| this(id, imageFile, new SessionPeriod(startTime, endTime), SessionStatus.valueOf(sessionStatus), allocateEnrollmentRule(price, capacity), new Enrollments()); | ||
| } | ||
|
|
||
| public Session(ImageFile imageFile, SessionPeriod period, SessionStatus sessionStatus, EnrollmentRule enrollmentRule) { | ||
| this(null, imageFile, period, sessionStatus, enrollmentRule, new Enrollments()); | ||
| } | ||
|
|
||
| public Session(ImageFile imageFile, SessionPeriod period, SessionStatus sessionStatus, EnrollmentRule enrollmentRule, Enrollments enrollments) { | ||
| this(null, imageFile, period, sessionStatus, enrollmentRule, enrollments); | ||
| } | ||
|
|
||
| public Session(Long id, ImageFile imageFile, SessionPeriod period, SessionStatus sessionStatus, EnrollmentRule enrollmentRule, Enrollments enrollments) { | ||
|
|
@@ -25,13 +36,12 @@ public int countEnrollments() { | |
| return enrollments.countEnrollments(); | ||
| } | ||
|
|
||
| public void enroll(Enrollment enrollment) { | ||
| public void enroll(Enrollment enrollment, Money money) { | ||
| validationRecruiting(); | ||
|
|
||
| enrollment.validateBelongsTo(this); | ||
| enrollment.validateBelongsTo(getId()); | ||
|
|
||
| enrollmentRule.validateMoney(enrollment.getMoney()); | ||
| enrollmentRule.validateCapacity(enrollments.countEnrollments()); | ||
| enrollmentRule.validate(money, countEnrollments()); | ||
|
|
||
| enrollments.enroll(enrollment); | ||
| } | ||
|
|
@@ -40,9 +50,77 @@ public Long getId() { | |
| return id; | ||
| } | ||
|
|
||
| public Long getImageId() { | ||
| return this.imageFile.getImageId(); | ||
| } | ||
|
|
||
| public String getSessionStatus() { | ||
| return this.sessionStatus.toString(); | ||
| } | ||
|
|
||
| public Integer getPrice() { | ||
| if (enrollmentRule.getType().equals(SessionType.PAID)) { | ||
| return ((PaidEnrollmentRule) this.enrollmentRule).getPrice(); | ||
| } | ||
|
|
||
| return null; | ||
|
Contributor
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. null보다 무료 강의의 기본을 0원으로 반환하는 것은 어떨까? |
||
| } | ||
|
|
||
| public Integer getCapacity() { | ||
| if (enrollmentRule.getType().equals(SessionType.PAID)) { | ||
| return ((PaidEnrollmentRule) this.enrollmentRule).getCapacity(); | ||
| } | ||
|
|
||
| return null; | ||
|
Contributor
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. null보다 무료 강의의 Integer 최대 값으로 반환하거나 무료 강의도 capacity 값을 가지는 것은 어떨까? |
||
| } | ||
|
|
||
| public LocalDateTime getStartTime() { | ||
| return this.period.getStartTime(); | ||
| } | ||
|
|
||
| public LocalDateTime getEndTime() { | ||
| return this.period.getEndTime(); | ||
| } | ||
|
|
||
| public SessionPeriod getPeriod() { | ||
| return this.period; | ||
| } | ||
|
|
||
| private static EnrollmentRule allocateEnrollmentRule(Integer price, Integer capacity) { | ||
| if (price != null) { | ||
| return new PaidEnrollmentRule(price, capacity); | ||
| } | ||
|
|
||
| return new FreeEnrollmentRule(); | ||
| } | ||
|
|
||
| private void validationRecruiting() { | ||
| if (!sessionStatus.enableRecruiting()) { | ||
| throw new IllegalArgumentException("모집중인 강의만 수강 신청할 수 있습니다."); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| Session session = (Session) o; | ||
| return Objects.equals(id, session.id) && Objects.equals(imageFile, session.imageFile) && Objects.equals(period, session.period) && sessionStatus == session.sessionStatus && Objects.equals(enrollmentRule, session.enrollmentRule) && Objects.equals(enrollments, session.enrollments); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(id, imageFile, period, sessionStatus, enrollmentRule, enrollments); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Session{" + | ||
| "id=" + id + | ||
| ", imageFile=" + imageFile + | ||
| ", period=" + period + | ||
| ", sessionStatus=" + sessionStatus + | ||
| ", enrollmentRule=" + enrollmentRule + | ||
| ", enrollments=" + enrollments + | ||
| '}'; | ||
| } | ||
| } | ||
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.
인터페이스에 너무 많은 메서드를 제공하고 있음.
이름 또한 EnrollmentRule이라 수강 신청 규칙을 판단하는 메서드만 가질 것으로 판단되는데 규칙 외의 메서드도 가지고 있는 것으로 판단됨
인터페이스의 메서드를 최소화하기 위한 설계 개선을 시도해 본다.