-
Notifications
You must be signed in to change notification settings - Fork 307
Lms step2 #126
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
Lms step2 #126
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
7836559
refactor(domain): step1 피드백 적용
Highjune 49789fb
refactor(domain): setter삭제, Answers에 delete()추가
Highjune b4b0382
refactor(domain): DeleteHistory에서 정적 팩토리 메서드에서 파라미터 도메인으로 변경"
Highjune 3d688c5
docs(README.md): 기능요구사항 작성
Highjune b39de98
test(domain): SessionTimeLineTest 테스트 선작성
Highjune 9c735e6
feat(domain): SessionTimeLine 객체 구현
Highjune 3d8a518
refactor(domain): SessionTimeLine 날짜 로직 체크 수정
Highjune 45b2955
feat(domain): SessionStatus Enum 객체 구현
Highjune 2e32239
feat(domain): SessionType enum 객체 구현
Highjune 4e64f85
feat(domain): SessionInfo 객체 구현
Highjune 08ac6b9
feat(domain): Session 객체 구현
Highjune b516e7b
feat(domain): Student 객체 구현 추가
Highjune 6a684ea
test(domain): StudentTest 에서 등록시 1 증가하는 테스트 먼저 생성
Highjune 38cb914
feat(domain): Student 를 Session에 등록
Highjune 944cd30
feat(domain): 수강신청시 인원 수 체크 로직
Highjune 25c83d2
test(domain): 수강신청시 최대 수강인원 이하면 예외 던지지 않는다
Highjune 2f7a502
test(domain): StudentTest 강의 상태에 따른 테스트 추가
Highjune 0312ae0
feat(domain): StudentRepository 추가
Highjune 9787ed5
test(domain): 기수에 따른 강의 조회 테스트 & 프로덕션 코드 추가
Highjune 6f18763
test(domain): CourseTest 존재하는 강의 조회 테스트 추가
Highjune 456423e
feat(domain): Course, CourseTest에서 유효하지 않는 기수 조회시 예외를 던진다
Highjune 65577c0
feat(domain): Course, CourseTest에서 유효성 추가
Highjune cefcc3e
feat(domain): SessionRepository 추가
Highjune 8058c79
docs(README.md): Course 체크리스트 업데이트
Highjune aee8314
feat(domain): Session에 등록하는 메서드명 변경
Highjune 39ad05a
feat(SessionEnrollment): 강의등록 객체 추가, 테스트 추가
Highjune 33d7889
feat(domain): SessionEnrollment 에 유효성 체크 추가
Highjune 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
8 changes: 8 additions & 0 deletions
8
src/main/java/nextstep/courses/domain/AlreadyEnrollmentException.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,8 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| public class AlreadyEnrollmentException extends RuntimeException{ | ||
|
|
||
| public AlreadyEnrollmentException(String message) { | ||
| super(message); | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/java/nextstep/courses/domain/CannotEnrollException.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,8 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| public class CannotEnrollException extends RuntimeException{ | ||
|
|
||
| public CannotEnrollException(String message) { | ||
| super(message); | ||
| } | ||
| } |
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,6 +1,8 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class Course { | ||
| private Long id; | ||
|
|
@@ -9,6 +11,8 @@ public class Course { | |
|
|
||
| private Long creatorId; | ||
|
|
||
| private final List<Session> sessions = new ArrayList<>(); | ||
|
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. 👍 |
||
|
|
||
| private LocalDateTime createdAt; | ||
|
|
||
| private LocalDateTime updatedAt; | ||
|
|
@@ -40,12 +44,39 @@ public LocalDateTime getCreatedAt() { | |
| return createdAt; | ||
| } | ||
|
|
||
| public Session getSession(int generation) { | ||
| validateGeneration(generation); | ||
| return this.sessions.get(generation - 1); | ||
| } | ||
|
|
||
| public void addSession(Session session) { | ||
| this.sessions.add(session); | ||
| } | ||
|
|
||
| private void validateGeneration(int generation) { | ||
| validateNegative(generation); | ||
| validateRange(generation); | ||
| } | ||
|
|
||
| private void validateNegative(int generation) { | ||
| if (generation <= 0) { | ||
| throw new IllegalArgumentException("기수는 1 기수 이상부터 시작합니다. 조회한 기수 = " + generation); | ||
| } | ||
| } | ||
|
|
||
| private void validateRange(int generation) { | ||
| if (sessions.size() < generation) { | ||
| throw new IllegalArgumentException("해당 기수의 강의는 존재하지 않습니다. 조회한 기수 = " + generation); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Course{" + | ||
| "id=" + id + | ||
| ", title='" + title + '\'' + | ||
| ", creatorId=" + creatorId + | ||
| ", sessions=" + sessions + | ||
| ", createdAt=" + createdAt + | ||
| ", updatedAt=" + updatedAt + | ||
| '}'; | ||
|
|
||
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,38 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public class Session { | ||
|
|
||
| private final SessionInfo sessionInfo; | ||
| private final SessionEnrollment sessionEnrollment; | ||
| private final SessionTimeLine sessionTimeLine; | ||
|
|
||
| public Session(Long courseId, Long ownerId, String title, String coverImageInfo, | ||
| SessionType sessionType, SessionStatus sessionStatus, | ||
| LocalDateTime createdAt, LocalDateTime closedAt, Long maxNumOfStudent) { | ||
|
|
||
| this(new SessionInfo(courseId, ownerId, title, coverImageInfo, sessionType), | ||
| new SessionEnrollment(sessionStatus, maxNumOfStudent), | ||
| new SessionTimeLine(createdAt, closedAt)); | ||
| } | ||
|
|
||
| public Session(SessionInfo sessionInfo, SessionEnrollment sessionEnrollment, | ||
| SessionTimeLine sessionTimeLine){ | ||
| this.sessionInfo = sessionInfo; | ||
| this.sessionEnrollment = sessionEnrollment; | ||
| this.sessionTimeLine = sessionTimeLine; | ||
| } | ||
|
|
||
| public void enroll(Student student) { | ||
| sessionEnrollment.enroll(student); | ||
| } | ||
|
|
||
| public Long totalStudentNum() { | ||
| return sessionEnrollment.totalStudentNum(); | ||
| } | ||
|
|
||
| public boolean isPositionFull() { | ||
| return sessionEnrollment.isPositionFull(); | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/main/java/nextstep/courses/domain/SessionEnrollment.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,41 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| public class SessionEnrollment { | ||
|
|
||
| private final SessionStatus sessionStatus; | ||
| private final Set<Student> students = new HashSet<>(); | ||
| private final Long capacity; | ||
|
|
||
| public SessionEnrollment(SessionStatus sessionStatus, Long capacity) { | ||
| this.sessionStatus = sessionStatus; | ||
| this.capacity = capacity; | ||
| } | ||
|
|
||
| public void enroll(Student student) { | ||
| if (!sessionStatus.canJoin()) { | ||
| throw new CannotEnrollException("현재는 수강신청을 할 수 없는 강의 상태입니다. 현재 강의 상태 = " + sessionStatus.name()); | ||
| } | ||
|
|
||
| if (isPositionFull()) { | ||
| throw new CannotEnrollException( | ||
| "현재 강의(Session)는 수강인원이 꽉 차서 더 이상 등록할 수 없습니다." + "최대인원 = " + capacity); | ||
| } | ||
|
|
||
| if (students.contains(student)) { | ||
| throw new AlreadyEnrollmentException(student + " 학생은 이미 등록한 상태입니다."); | ||
| } | ||
| this.students.add(student); | ||
| } | ||
|
|
||
| public Long totalStudentNum() { | ||
| return Long.valueOf(students.size()); | ||
| } | ||
|
|
||
| public boolean isPositionFull() { | ||
| return totalStudentNum() == capacity; | ||
| } | ||
|
|
||
| } |
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,18 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| public class SessionInfo { | ||
|
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. 👍 |
||
|
|
||
| private final Long courseId; | ||
| private final Long ownerId; | ||
| private final String title; | ||
| private final String coverImageInfo; | ||
| private final SessionType sessionType; | ||
|
|
||
| public SessionInfo(Long courseId, Long ownerId, String title, String coverImageInfo, SessionType sessionType) { | ||
| this.courseId = courseId; | ||
| this.ownerId = ownerId; | ||
| this.title = title; | ||
| this.coverImageInfo = coverImageInfo; | ||
| this.sessionType = sessionType; | ||
| } | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
src/main/java/nextstep/courses/domain/SessionRepository.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,12 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface SessionRepository { | ||
|
|
||
| int save(String session); | ||
|
|
||
| Session findById(Long id); | ||
|
|
||
| List<Session> findByCourseId(Long courseId); | ||
| } |
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; | ||
|
|
||
| public enum SessionStatus { | ||
|
|
||
| READY("준비중"), | ||
| OPENED("모집중"), | ||
| CLSOED("종료") | ||
| ; | ||
|
|
||
| private String name; | ||
|
|
||
| SessionStatus(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public boolean canJoin() { | ||
| return this.equals(OPENED); | ||
| } | ||
|
|
||
| } |
21 changes: 21 additions & 0 deletions
21
src/main/java/nextstep/courses/domain/SessionTimeLine.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,21 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public class SessionTimeLine { | ||
|
|
||
| private LocalDateTime createAt; | ||
| private LocalDateTime closeAt; | ||
|
|
||
| public SessionTimeLine(LocalDateTime createAt, LocalDateTime closeAt) { | ||
| validateInterval(createAt, closeAt); | ||
| this.createAt = createAt; | ||
| this.closeAt = closeAt; | ||
| } | ||
|
|
||
| private void validateInterval(LocalDateTime createAt, LocalDateTime closeAt) { | ||
| if (createAt.isAfter(closeAt)) { | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| public enum SessionType { | ||
|
|
||
| FREE("무료"), | ||
| CHANGED("유료") | ||
| ; | ||
|
|
||
| private String name; | ||
| SessionType(String name) { | ||
| this.name = name; | ||
| } | ||
| } |
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,16 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| public class Student { | ||
|
|
||
| private final Long studentId; | ||
| private final Long sessionId; | ||
|
|
||
| public Student(Long studentId, Long sessionId) { | ||
| this.studentId = studentId; | ||
| this.sessionId = sessionId; | ||
| } | ||
|
|
||
| public void enroll(Session session) { | ||
| session.enroll(this); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/nextstep/courses/domain/StudentRepository.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,10 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface StudentRepository { | ||
|
|
||
| int save(Student student); | ||
|
|
||
| List<Student> findBySessionId(Long sessionId); | ||
| } |
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
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.
todo list 작성 👍