-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathSession.java
More file actions
43 lines (35 loc) · 1.3 KB
/
Session.java
File metadata and controls
43 lines (35 loc) · 1.3 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.session;
import nextstep.courses.CannotEnrollException;
import nextstep.courses.strategy.PaymentStrategy;
import nextstep.payments.domain.Payment;
import nextstep.users.domain.NsUser;
import java.time.LocalDate;
public class Session {
private final SessionImage image;
private final SessionDate date;
private final SessionState state;
private final Enrollment enrollment;
private final PaymentStrategy paymentStrategy;
public Session(SessionImage image, SessionDate date, SessionState state, Enrollment enrollment, PaymentStrategy paymentStrategy) {
this.image = image;
this.date = date;
this.state = state;
this.enrollment = enrollment;
this.paymentStrategy = paymentStrategy;
}
public void applySession(NsUser user, LocalDate enrollDate, Payment payment) {
if (!canApply(enrollDate, payment)) {
throw new CannotEnrollException("등록 불가능한 상태입니다.");
}
this.enrollment.enroll(user);
}
private boolean canApply(LocalDate enrollDate, Payment payment) {
if (!state.canRecruit()) {
return false;
}
if (!date.isBefore(enrollDate)) {
return false;
}
return paymentStrategy.payable(payment);
}
}