-
Notifications
You must be signed in to change notification settings - Fork 308
๐ 3๋จ๊ณ - ์๊ฐ์ ์ฒญ(DB ์ ์ฉ) #802
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
Changes from all commits
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,17 +1,41 @@ | ||
| package nextstep.courses.domain.image; | ||
|
|
||
| public class SessionCoverImage { | ||
| private final Long id; | ||
| private final Long sessionId; | ||
| private final SessionImageDimension dimension; | ||
| private final SessionImageExtension extension; | ||
| private final SessionImageCapacity capacity; | ||
|
|
||
| public SessionCoverImage(int width, int height, String extension, long bytes) { | ||
| this(new SessionImageDimension(width, height), SessionImageExtension.from(extension), new SessionImageCapacity(bytes)); | ||
| public SessionCoverImage(Long sessionId, int width, int height, String extension, long bytes) { | ||
| this(null, sessionId, new SessionImageDimension(width, height), SessionImageExtension.from(extension), new SessionImageCapacity(bytes)); | ||
| } | ||
|
|
||
| public SessionCoverImage(SessionImageDimension dimension, SessionImageExtension extension, SessionImageCapacity capacity) { | ||
| public SessionCoverImage(Long id, Long sessionId, SessionImageDimension dimension, SessionImageExtension extension, SessionImageCapacity capacity) { | ||
| this.id = id; | ||
| this.sessionId = sessionId; | ||
| this.dimension = dimension; | ||
| this.extension = extension; | ||
| this.capacity = capacity; | ||
| } | ||
|
|
||
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public Long getSessionId() { | ||
| return sessionId; | ||
| } | ||
|
|
||
| public SessionImageDimension getDimension() { | ||
| return dimension; | ||
| } | ||
|
|
||
| public SessionImageExtension getExtension() { | ||
| return extension; | ||
| } | ||
|
|
||
| public SessionImageCapacity getCapacity() { | ||
| return capacity; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,4 +26,7 @@ private void validate(long bytes) { | |
| } | ||
| } | ||
|
|
||
| public long bytes() { | ||
| return bytes; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package nextstep.courses.domain.image; | ||
|
|
||
| public interface SessionImageRepository { | ||
| int save(SessionCoverImage image); | ||
|
|
||
| SessionCoverImage findById(Long id); | ||
|
|
||
| SessionCoverImage findBySessionId(Long sessionId); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,42 @@ | ||
| package nextstep.courses.domain.registration; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.Objects; | ||
|
|
||
| public class Registration { | ||
| private final Long id; | ||
| private final Long sessionId; | ||
| private final Long studentId; | ||
| private final LocalDateTime enrolledAt; | ||
|
|
||
| public Registration(Long sessionId, Long studentId) { | ||
| this(sessionId, studentId, LocalDateTime.now()); | ||
| this(null, sessionId, studentId, LocalDateTime.now()); | ||
| } | ||
|
|
||
| public Registration(Long sessionId, Long studentId, LocalDateTime enrolledAt) { | ||
| public Registration(Long id, Long sessionId, Long studentId, LocalDateTime enrolledAt) { | ||
| this.id = id; | ||
| this.sessionId = sessionId; | ||
| this.studentId = studentId; | ||
| this.enrolledAt = enrolledAt; | ||
| } | ||
|
|
||
| public boolean contains(Long studentId) { | ||
| return this.studentId == studentId; | ||
| return Objects.equals(this.studentId, studentId); | ||
| } | ||
|
|
||
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public Long getSessionId() { | ||
| return sessionId; | ||
| } | ||
|
|
||
| public Long getStudentId() { | ||
| return studentId; | ||
| } | ||
|
|
||
| public LocalDateTime getEnrolledAt() { | ||
| return enrolledAt; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package nextstep.courses.domain.registration; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface RegistrationRepository { | ||
| int save(Registration registration); | ||
|
|
||
| Registration findById(Long id); | ||
|
|
||
| List<Registration> findBySessionId(Long sessionId); | ||
|
|
||
| int countBySessionId(Long sessionId); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,44 @@ | ||
| package nextstep.courses.domain.registration; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| public class Registrations { | ||
| private final List<Registration> registrations; | ||
|
|
||
| public Registrations() { | ||
| this(new ArrayList<>()); | ||
| } | ||
|
|
||
| public Registrations(List<Registration> registrations) { | ||
| this.registrations = registrations; | ||
| } | ||
|
|
||
| public Registrations add(Registration registration) { | ||
| List<Registration> newList = new ArrayList<>(registrations); | ||
| newList.add(registration); | ||
| return new Registrations(newList); | ||
| } | ||
|
|
||
| public int count() { | ||
| return registrations.size(); | ||
| } | ||
|
|
||
| public boolean contains(Long studentId) { | ||
| return registrations.stream() | ||
| .anyMatch(r -> r.contains(studentId)); | ||
| } | ||
|
|
||
| private final List<Registration> registrations; | ||
|
|
||
| public Registrations() { | ||
| this(new ArrayList<>()); | ||
| } | ||
|
|
||
| public Registrations(List<Registration> registrations) { | ||
| this.registrations = new ArrayList<>(registrations); | ||
| } | ||
|
|
||
| public Registrations add(Registration registration) { | ||
| validateDuplicateRegistration(registration); | ||
| List<Registration> newList = new ArrayList<>(registrations); | ||
| newList.add(registration); | ||
| return new Registrations(newList); | ||
| } | ||
|
|
||
| private void validateDuplicateRegistration(Registration registration) { | ||
| if (isAlreadyRegistered(registration.getStudentId())) { | ||
| throw new IllegalArgumentException("์ด๋ฏธ ์๊ฐ์ ์ฒญํ ํ์์ ๋๋ค."); | ||
| } | ||
| } | ||
|
|
||
| public boolean isAlreadyRegistered(long studentId) { | ||
| return registrations.stream() | ||
| .anyMatch(registration -> registration.getStudentId().equals(studentId)); | ||
| } | ||
|
|
||
| public void validateCapacity(int maxCapacity) { | ||
| if (count() > maxCapacity) { | ||
| throw new IllegalStateException("์ต๋ ์๊ฐ ์ธ์์ ์ด๊ณผํ ์ ์์ต๋๋ค."); | ||
| } | ||
| } | ||
|
|
||
| public int count() { | ||
| return registrations.size(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,33 @@ | ||
| package nextstep.courses.domain.session; | ||
|
|
||
| import nextstep.courses.domain.session.type.FreeType; | ||
| import nextstep.courses.domain.session.type.SessionType; | ||
| import nextstep.courses.domain.registration.Registration; | ||
| import nextstep.courses.domain.registration.Registrations; | ||
|
|
||
| public class Enrollment { | ||
| private SessionState state; | ||
| private SessionType type; | ||
|
|
||
| public Enrollment() { | ||
| this(SessionState.PREPARING, new FreeType()); | ||
| } | ||
|
|
||
| public Enrollment(SessionType type) { | ||
| this(SessionState.PREPARING, type); | ||
| } | ||
|
|
||
| public Enrollment(SessionState state, SessionType type) { | ||
| private final Session 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. Session์ผ๋ก ์์กด ๊ด๊ณ๋ฅผ ๊ฐ์ง๋ค๋ณด๋ Enrollment ์์ฑ์๋ ์ด๋ ค์์ด ์์ ๊ฒ ๊ฐ๋ค. |
||
| private final SessionState state; | ||
| private final SessionPolicy policy; | ||
| private final Registrations registrations; | ||
|
|
||
| public Enrollment(Session session, SessionState state, SessionPolicy policy, Registrations registrations) { | ||
| validateState(state); | ||
| this.session = session; | ||
| this.state = state; | ||
| this.type = type; | ||
| this.policy = policy; | ||
| this.registrations = registrations; | ||
| } | ||
|
|
||
| public void enroll(long payAmount) { | ||
| validateState(); | ||
| this.type = type.enroll(payAmount); | ||
| } | ||
| public Registration enroll(long payAmount, long userId) { | ||
| if (registrations.isAlreadyRegistered(userId)) { | ||
| throw new IllegalArgumentException("์ด๋ฏธ ์๊ฐ์ ์ฒญํ ํ์์ ๋๋ค."); | ||
| } | ||
|
|
||
| public void open() { | ||
| this.state = state.open(); | ||
| } | ||
| policy.validate(payAmount, registrations); | ||
|
|
||
| public void close() { | ||
| this.state = state.close(); | ||
| return new Registration(session.getId(), userId); | ||
| } | ||
|
|
||
| private void validateState() { | ||
| private void validateState(SessionState state) { | ||
| if (!state.canEnroll()) { | ||
| throw new IllegalStateException("๋ชจ์ง์ค์ธ ๊ฐ์๋ง ์๊ฐ์ ์ฒญ์ด ๊ฐ๋ฅํฉ๋๋ค."); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,74 @@ | ||
| package nextstep.courses.domain.session; | ||
|
|
||
| import java.util.List; | ||
| import nextstep.courses.domain.BaseEntity; | ||
| import nextstep.courses.domain.course.Course; | ||
| import nextstep.courses.domain.image.SessionCoverImage; | ||
| import nextstep.courses.domain.registration.Registration; | ||
| import nextstep.courses.domain.registration.Registrations; | ||
|
|
||
| public class Session extends BaseEntity { | ||
| private final Course course; | ||
| private final Term term; | ||
| private final SessionCoverImage cover; | ||
| private final SessionPeriod period; | ||
| private final Enrollment enrollment; | ||
|
|
||
| public Session(Course course, int term, SessionCoverImage cover, String startDay, String endDay) { | ||
| this(null, course, new Term(term), cover, new SessionPeriod(startDay, endDay), new Enrollment()); | ||
| } | ||
|
|
||
| public Session(Long id, Course course, Term term, SessionCoverImage cover, SessionPeriod period, Enrollment enrollment) { | ||
| super(id); | ||
| this.course = course; | ||
| this.term = term; | ||
| this.cover = cover; | ||
| this.period = period; | ||
| this.enrollment = enrollment; | ||
| } | ||
|
|
||
| public void enroll(long payAmount) { | ||
| enrollment.enroll(payAmount); | ||
| } | ||
|
|
||
| public void open() { | ||
| enrollment.open(); | ||
| } | ||
|
|
||
| public void close() { | ||
| enrollment.close(); | ||
| } | ||
| private final Long courseId; | ||
| private final Term term; | ||
| private final SessionPeriod period; | ||
| private final SessionCoverImage coverImage; | ||
| private final SessionPolicy sessionPolicy; | ||
| private SessionState state; | ||
|
|
||
| public Session(Long courseId, int term, String startDay, String endDay, SessionCoverImage coverImage) { | ||
| this(null, courseId, new Term(term), new SessionPeriod(startDay, endDay), SessionState.PREPARING, new SessionPolicy(), coverImage); | ||
| } | ||
|
|
||
| public Session(Long courseId, int term, String startDay, String endDay, SessionPolicy sessionPolicy, SessionCoverImage coverImage) { | ||
| this(null, courseId, new Term(term), new SessionPeriod(startDay, endDay), SessionState.PREPARING, sessionPolicy, coverImage); | ||
| } | ||
|
|
||
| public Session(Long id, Long courseId, Term term, SessionPeriod period, SessionState state, SessionPolicy sessionPolicy, SessionCoverImage coverImage) { | ||
| super(id); | ||
| this.courseId = courseId; | ||
| this.term = term; | ||
| this.period = period; | ||
| this.state = state; | ||
| this.sessionPolicy = sessionPolicy; | ||
| this.coverImage = coverImage; | ||
| } | ||
|
|
||
| public Enrollment enrollment(Registrations registrations) { | ||
| return new Enrollment(this, state, sessionPolicy, registrations); | ||
| } | ||
|
|
||
| public Enrollment enrollment(List<Registration> registrations) { | ||
| return new Enrollment(this, state, sessionPolicy, new Registrations(registrations)); | ||
| } | ||
|
|
||
| public void open() { | ||
| this.state = state.open(); | ||
| } | ||
|
|
||
| public void close() { | ||
| this.state = state.close(); | ||
| } | ||
|
|
||
| public Long getCourseId() { | ||
| return courseId; | ||
| } | ||
|
|
||
| public Term getTerm() { | ||
| return term; | ||
| } | ||
|
|
||
| public SessionPeriod getPeriod() { | ||
| return period; | ||
| } | ||
|
|
||
| public SessionState getState() { | ||
| return state; | ||
| } | ||
|
|
||
| public SessionPolicy getSessionPolicy() { | ||
| return sessionPolicy; | ||
| } | ||
|
|
||
| public SessionCoverImage getCoverImage() { | ||
| return coverImage; | ||
| } | ||
| } |
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.
๐