-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy pathPaidSession.java
68 lines (58 loc) · 2.68 KB
/
PaidSession.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
package nextstep.courses.domain.session;
import nextstep.courses.CannotSignUpException;
import nextstep.courses.common.SystemTimeStamp;
import nextstep.payments.domain.Payment;
import nextstep.users.domain.NsUser;
import java.time.LocalDate;
import java.time.LocalDateTime;
public class PaidSession extends Session {
private int maxStudentCount;
private Long sessionFee;
public static PaidSession feeOf(long id, String title, long courseId,
EnrollmentStatus enrollmentStatus, LocalDate startDate,
LocalDate endDate, LocalDateTime createdAt, LocalDateTime updatedAt,
int maxStudentCount, Long sessionFee) {
return new PaidSession(new SessionInfo(id, title, courseId, SessionType.PAID),
new SessionPlan(enrollmentStatus, startDate, endDate),
new SystemTimeStamp(createdAt, updatedAt),
maxStudentCount, sessionFee);
}
public PaidSession(SessionInfo sessionInfo, SessionPlan sessionPlan, SystemTimeStamp systemTimeStamp,
int maxStudentCount, Long sessionFee) {
super(sessionInfo, sessionPlan, systemTimeStamp);
this.maxStudentCount = maxStudentCount;
this.sessionFee = sessionFee;
}
@Override
public void signUp(NsUser student) {
validateAvailableStudentCount();
validatePayInfo(student, getPayInfo(student));
super.signUp(student);
}
private Payment getPayInfo(NsUser student) {
return Payment.paidOf("tmp", super.getId(), student.getId(), this.sessionFee); // 결제가 완료됐다고 가정하기 위함.
}
private void validatePayInfo(NsUser student, Payment payment) {
if (payment.isNotSameSessionId(this.getId())) {
throw new CannotSignUpException("해당 강의 결제이력이 없습니다.");
}
if (payment.isNotSameStudentId(student.getId())) {
throw new CannotSignUpException("결제자와 신청자의 정보가 일치하지 않습니다.");
}
if (payment.isNotSameSessionFee(sessionFee)) {
throw new CannotSignUpException("결제금액과 수강료가 일치하지 않습니다.");
}
}
private void validateAvailableStudentCount() throws CannotSignUpException {
if (maxStudentCount == super.getStudentCount()) {
throw new CannotSignUpException("최대 수강 인원을 초과했습니다.");
}
}
@Override
public String toString() {
return "PaidSession{" +
"maxStudentCount=" + maxStudentCount +
", sessionFee=" + sessionFee +
'}';
}
}