-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathSession.java
More file actions
66 lines (52 loc) · 1.67 KB
/
Session.java
File metadata and controls
66 lines (52 loc) · 1.67 KB
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
package nextstep.courses.domain;
import nextstep.payments.domain.Payment;
import java.util.List;
import java.util.stream.Collectors;
public abstract class Session {
protected Long id;
protected String name;
protected Period period;
protected Image coverImage;
protected SessionStatus status;
protected Students registeredStudents;
public Session(Long id, String name, Period period, Image coverImage, SessionStatus status) {
this.id = id;
this.name = name;
this.period = period;
this.coverImage = coverImage;
this.status = status;
this.registeredStudents = new Students();
}
public List<Long> getStudentIds() {
return registeredStudents.getStudents().stream()
.map(Student::getId)
.collect(Collectors.toList());
}
public Students getRegisteredStudent() {
return registeredStudents;
}
public Image getCoverImage() {
return coverImage;
}
public String getName() {
return name;
}
public Period getPeriod() {
return period;
}
public SessionStatus getStatus() {
return status;
}
public Long getId() {
return id;
}
public void register(Long studentId, Payment payment) {
if (status != SessionStatus.RECRUITING) {
throw new IllegalStateException("수강 신청은 모집중일 때만 가능합니다.");
}
validateRegistration(studentId, payment);
registeredStudents.addStudent(new Student(studentId));
}
protected abstract void validateRegistration(Long studentId, Payment payment);
public abstract SessionType getType();
}