-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathSession.java
More file actions
43 lines (33 loc) · 1.26 KB
/
Session.java
File metadata and controls
43 lines (33 loc) · 1.26 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
package nextstep.courses.domain;
import nextstep.courses.CannotEnrollSessionException;
import nextstep.payments.domain.EnrollmentPolicy;
import nextstep.payments.domain.Payment;
import java.time.LocalDate;
public class Session {
private final LocalDate startDate;
private final LocalDate endDate;
private final CoverImage coverImage;
private final SessionStatus status;
private final EnrollmentPolicy enrollmentPolicy;
private int currentEnrolledCount = 0;
public Session(LocalDate startDate,
LocalDate endDate,
CoverImage coverImage,
SessionStatus status,
EnrollmentPolicy enrollmentPolicy) {
this.startDate = startDate;
this.endDate = endDate;
this.coverImage = coverImage;
this.status = status;
this.enrollmentPolicy = enrollmentPolicy;
}
public void enroll(Payment payment) {
if (!this.status.canEnroll()) {
throw new CannotEnrollSessionException("모집 중이 아닙니다.");
}
if (!enrollmentPolicy.canEnroll(currentEnrolledCount, payment)) {
throw new CannotEnrollSessionException("수강 조건이 맞지 않습니다.");
}
currentEnrolledCount++;
}
}