-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy pathSession.java
103 lines (83 loc) · 2.95 KB
/
Session.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package nextstep.courses.domain.session;
import nextstep.courses.CannotSignUpException;
import nextstep.courses.common.SystemTimeStamp;
import nextstep.courses.domain.Student;
import nextstep.courses.domain.image.SessionImage;
import nextstep.qna.NotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import static nextstep.courses.domain.session.RegistrationState.*;
public class Session {
private SessionInfo sessionInfo;
private List<SessionImage> sessionImage;
private List<Student> students;
private SessionPlan sessionPlan;
private SystemTimeStamp systemTimeStamp;
public Session(SessionInfo sessionInfo, SessionPlan sessionPlan, SystemTimeStamp systemTimeStamp) {
this.sessionInfo = sessionInfo;
this.students = new ArrayList<>(Collections.emptyList());
this.sessionPlan = sessionPlan;
this.sessionImage = new ArrayList<>(Collections.emptyList());;
this.systemTimeStamp = systemTimeStamp;
}
public void signUp(Student student) {
validateEnrollmentStatus();
students.add(student);
}
private void validateEnrollmentStatus() {
if (!EnrollmentStatus.canSignUp(this.sessionPlan.getEnrollmentStatus())) {
throw new CannotSignUpException("강의 모집중이 아닙니다.");
}
}
public void saveImage(SessionImage sessionImage) {
this.sessionImage.add(sessionImage);
}
public void cancelStudent(Student student) {
Student validateStudent = validateIsAStudent(student);
validateStudent.isCanceled();
}
public void approveStudent(Student student) {
Student validatedStudent = validateIsAStudent(student);
validatedStudent.isApproved();
}
private Student validateIsAStudent(Student student) {
return this.getAllStudents().stream()
.filter(x -> x.getNsUserId() == student.getNsUserId())
.findFirst()
.orElseThrow(NotFoundException::new);
}
public int getStudentCount() {
return students.size();
}
public Long getId() {
return sessionInfo.getId();
}
public long getCourseId() {
return sessionInfo.getCourseId();
}
public String getTitle() {
return sessionInfo.getTitle();
}
public SessionType getSessionType() {
return sessionInfo.getSessionType();
}
public List<Student> getStudents() {
return students.stream()
.filter(student -> student.getRegistrationState() == RegistrationState.APPROVED)
.collect(Collectors.toList());
}
public List<Student> getAllStudents() {
return students;
}
public SessionPlan getSessionPlan() {
return sessionPlan;
}
public SystemTimeStamp getSystemTimeStamp() {
return systemTimeStamp;
}
public int getImageCount() {
return sessionImage.size();
}
}