-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3단계 - 수강신청(DB 적용) #647
base: yunji1201
Are you sure you want to change the base?
3단계 - 수강신청(DB 적용) #647
Changes from 3 commits
64634ad
11ca7b1
8f0c531
5e18079
630f407
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package nextstep.courses.domain; | ||
|
||
public interface ImageRepository { | ||
int save(Image image); | ||
|
||
Image findById(Long id); | ||
|
||
int update(Image image); | ||
|
||
int deleteById(Long id); | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package nextstep.courses.domain; | ||
|
||
import nextstep.courses.domain.session.Session; | ||
|
||
public interface SessionRepository { | ||
int save(Session session); | ||
|
||
Session findById(Long id); | ||
|
||
int update(Session session); | ||
|
||
int deleteById(Long id); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package nextstep.courses.domain.session; | ||
|
||
import nextstep.courses.constants.SessionStatus; | ||
import nextstep.courses.domain.Image; | ||
|
||
import java.time.LocalDate; | ||
|
||
public class FreeSession extends Session { | ||
public FreeSession(Long id, Long courseId, String title, LocalDate startDate, LocalDate endDate, Image sessionImage) { | ||
super(id, courseId, title, startDate, endDate, sessionImage, SessionStatus.READY); | ||
} | ||
|
||
@Override | ||
public void enroll(int payment) { | ||
if (status != SessionStatus.OPEN) { | ||
throw new IllegalStateException("수강 신청은 모집중인 상태에서만 가능합니다."); | ||
} | ||
enrollCount++; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package nextstep.courses.domain.session; | ||
|
||
import nextstep.courses.constants.SessionStatus; | ||
import nextstep.courses.domain.Image; | ||
|
||
import java.time.LocalDate; | ||
|
||
public class PaidSession extends Session { | ||
private int maxEnrollment; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 필드를 굳이 구현체에 따라 나눌 필요가 있을까요 ? 디비상으로는 무료강의도 값을 가지고 있긴 할텐데요! |
||
private int sessionFee; | ||
|
||
public abstract class Session { | ||
protected Long courseId; | ||
|
||
public Session(Long id, Long courseId, String title, LocalDate startDate, LocalDate endDate, Image sessionImage, SessionStatus status) { | ||
this.courseId = courseId; | ||
} | ||
} | ||
|
||
public PaidSession(Long courseId, String title, LocalDate startDate, LocalDate endDate, Image sessionImage, int maxEnrollment, int sessionFee) { | ||
super(null, courseId, title, startDate, endDate, sessionImage, SessionStatus.READY); | ||
this.maxEnrollment = maxEnrollment; | ||
this.sessionFee = sessionFee; | ||
} | ||
|
||
@Override | ||
public void enroll(int payment) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요거는 꼭 그래야되는 건 아닌데, 유효성검사의 책임을 다른 클래스로 위임하는건 어떨까요 ? |
||
if (status != SessionStatus.OPEN) { | ||
throw new IllegalStateException("수강 신청은 모집중인 상태에서만 가능합니다."); | ||
} | ||
if (enrollCount >= maxEnrollment) { | ||
throw new IllegalStateException("수강 인원이 초과되었습니다."); | ||
} | ||
if (payment != sessionFee) { | ||
throw new IllegalArgumentException("결제 금액이 수강료와 일치하지 않습니다."); | ||
} | ||
enrollCount++; | ||
} | ||
|
||
public int getSessionFee() { | ||
return sessionFee; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package nextstep.courses.domain.session; | ||
|
||
import nextstep.courses.constants.SessionStatus; | ||
import nextstep.courses.domain.Image; | ||
|
||
import java.time.LocalDate; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
public abstract class Session { | ||
protected Long id; | ||
protected Long courseId; | ||
protected String title; | ||
protected LocalDate startDate; | ||
protected LocalDate endDate; | ||
protected Image sessionImage; | ||
protected int enrollCount; | ||
protected SessionStatus status; | ||
|
||
public Session(Long id, Long courseId, String title, LocalDate startDate, LocalDate endDate, Image sessionImage, SessionStatus status) { | ||
validateDate(startDate, endDate); | ||
this.id = id; | ||
this.courseId = courseId; | ||
this.title = title; | ||
this.startDate = startDate; | ||
this.endDate = endDate; | ||
this.sessionImage = sessionImage; | ||
this.status = status; | ||
this.enrollCount = 0; | ||
} | ||
|
||
|
||
public Session(String title, LocalDate startDate, LocalDate endDate, Image sessionImage, SessionStatus status) { | ||
this(null, null, title, startDate, endDate, sessionImage, status); | ||
} | ||
|
||
private void validateDate(LocalDate startDate, LocalDate endDate) { | ||
if (startDate.isAfter(endDate)) { | ||
throw new IllegalArgumentException("시작일은 종료일 이전이어야 합니다."); | ||
} | ||
} | ||
|
||
public void startEnrollment() { | ||
this.status = SessionStatus.OPEN; | ||
} | ||
|
||
public void closeEnrollment() { | ||
this.status = SessionStatus.CLOSED; | ||
} | ||
|
||
public abstract void enroll(int payment); | ||
|
||
public int getEnrolledCount() { | ||
return enrollCount; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public Long getCourseId() { | ||
return courseId; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public long getDuration() { | ||
return ChronoUnit.DAYS.between(startDate, endDate); | ||
} | ||
|
||
public LocalDate getStartTime() { | ||
return this.startDate; | ||
} | ||
|
||
public LocalDate getEndTime() { | ||
return this.endDate; | ||
} | ||
|
||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이미지가 세션아이디를 알아야 하는 이유가 있을까요 ?