-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathPaidSession.java
More file actions
39 lines (34 loc) · 1.45 KB
/
PaidSession.java
File metadata and controls
39 lines (34 loc) · 1.45 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
package nextstep.courses.domain;
import nextstep.payments.domain.Payment;
public class PaidSession extends Session {
private Capacity maxCapacity;
private TuitionFee tuitionFee;
public PaidSession(Long id, String name, Period period, Image coverImage,
SessionStatus status, int maxCapacity, int tuitionFee) {
super(id, name, period, coverImage, status);
this.maxCapacity = new Capacity(maxCapacity);
this.tuitionFee = new TuitionFee(tuitionFee);
}
@Override
protected void validateRegistration(Long studentId, Payment payment) {
if (registeredStudents.size() >= maxCapacity.getValue()) {
throw new IllegalStateException("수강 인원을 초과하였습니다.");
}
if (payment == null) {
throw new IllegalArgumentException("결제 정보가 없습니다.");
}
if (!this.id.equals(payment.getSessionId())) {
throw new IllegalArgumentException("결제한 강의와 일치하지 않습니다.");
}
if (!studentId.equals(payment.getNsUserId())) {
throw new IllegalArgumentException("결제한 사용자와 일치하지 않습니다.");
}
if (!this.tuitionFee.isSameAmount(payment.getAmount())) {
throw new IllegalArgumentException("결제 금액과 일치하지 않습니다.");
}
}
@Override
public SessionType getType() {
return SessionType.PAID;
}
}