Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
## 온라인 코드 리뷰 과정
* [텍스트와 이미지로 살펴보는 온라인 코드 리뷰 과정](https://github.com/next-step/nextstep-docs/tree/master/codereview)

## 테스트
## 단위 테스트
### Question
- [x] 로그인 사용자와 질문 작성자가 같고 답변이 없는 경우 질문을 삭제할 수 있다
- [x] 로그인 사용자와 질문 작성자가 다른 경우 질문을 삭제할 수 없다
Expand Down Expand Up @@ -38,3 +38,18 @@

### Course
- [x] 과정은 여러 강의를 가질 수 있다

## 통합 테스트

### 강의 (Session)
- [x] 강의를 저장할 수 있다
- [x] 강의를 ID로 조회할 수 있다
- [x] 과정 ID로 강의 목록을 조회할 수 있다

### 커버 이미지 (CoverImage)
- [x] 커버 이미지를 저장할 수 있다
- [x] 강의 ID로 커버 이미지를 조회할 수 있다

### 수강신청 (Enrollment)
- [x] 수강신청을 저장할 수 있다
- [x] 강의 ID로 수강생 목록을 조회할 수 있다
22 changes: 19 additions & 3 deletions src/main/java/nextstep/core/domain/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,32 @@

public class BaseEntity {
private Long id;
private LocalDateTime createdDate = LocalDateTime.now();
private LocalDateTime updatedDate;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;

protected BaseEntity() {}
protected BaseEntity() {
this.createdAt = LocalDateTime.now();
}

protected BaseEntity(Long id) {
this(id, LocalDateTime.now(), null);
}

protected BaseEntity(Long id, LocalDateTime createdAt, LocalDateTime updatedAt) {
this.id = id;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
}

public Long getId() {
return id;
}

public LocalDateTime getCreatedAt() {
return createdAt;
}

public LocalDateTime getUpdatedAt() {
return updatedAt;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package nextstep.core.domain;

import java.time.LocalDateTime;

public class SoftDeletableBaseEntity extends BaseEntity {
private boolean deleted = false;

Expand All @@ -9,6 +11,10 @@ protected SoftDeletableBaseEntity(Long id) {
super(id);
}

protected SoftDeletableBaseEntity(Long id, LocalDateTime createdAt, LocalDateTime updatedAt) {
super(id, createdAt, updatedAt);
}

public boolean isDeleted() {
return deleted;
}
Expand Down
26 changes: 9 additions & 17 deletions src/main/java/nextstep/courses/domain/Course.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package nextstep.courses.domain;

import java.time.LocalDateTime;
import nextstep.core.domain.SoftDeletableBaseEntity;
import nextstep.courses.domain.session.Session;
import nextstep.courses.domain.session.Sessions;

public class Course {
public class Course extends SoftDeletableBaseEntity {
private final Sessions sessions = new Sessions();
private Long id;
private String title;
private Long creatorId;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;

public Course() {
}
Expand All @@ -20,11 +18,9 @@ public Course(String title, Long creatorId) {
}

public Course(Long id, String title, Long creatorId, LocalDateTime createdAt, LocalDateTime updatedAt) {
this.id = id;
super(id, createdAt, updatedAt);
this.title = title;
this.creatorId = creatorId;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
}

public String getTitle() {
Expand All @@ -35,10 +31,6 @@ public Long getCreatorId() {
return creatorId;
}

public LocalDateTime getCreatedAt() {
return createdAt;
}

public void addSession(Session session) {
sessions.add(session);
}
Expand All @@ -50,11 +42,11 @@ public int sessionCount() {
@Override
public String toString() {
return "Course{" +
"id=" + id +
", title='" + title + '\'' +
", creatorId=" + creatorId +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
'}';
"id=" + getId() +
", title='" + title + '\'' +
", creatorId=" + creatorId +
", createdAt=" + getCreatedAt() +
", updatedAt=" + getUpdatedAt() +
'}';
}
}
10 changes: 10 additions & 0 deletions src/main/java/nextstep/courses/domain/CoverImageRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package nextstep.courses.domain;

import nextstep.courses.domain.image.CoverImage;

public interface CoverImageRepository {

int save(CoverImage coverImage);

CoverImage findBySessionId(Long sessionId);
}
11 changes: 11 additions & 0 deletions src/main/java/nextstep/courses/domain/EnrollmentRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package nextstep.courses.domain;

import java.util.List;
import nextstep.courses.domain.enrollment.Enrollment;

public interface EnrollmentRepository {

Long save(Enrollment enrollment);

List<Enrollment> findBySessionId(Long sessionId);
}
14 changes: 14 additions & 0 deletions src/main/java/nextstep/courses/domain/SessionRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package nextstep.courses.domain;

import java.util.List;
import nextstep.courses.domain.session.Session;

public interface SessionRepository {

Long save(Session session);

Session findById(Long id);

List<Session> findByCourseId(Long courseId);

}
27 changes: 27 additions & 0 deletions src/main/java/nextstep/courses/domain/enrollment/Enrollment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package nextstep.courses.domain.enrollment;

import java.time.LocalDateTime;
import nextstep.core.domain.BaseEntity;

public class Enrollment extends BaseEntity {
private final Long sessionId;
private final Long userId;

public Enrollment(Long sessionId, Long userId) {
this(null, sessionId, userId, LocalDateTime.now(), null);
}

public Enrollment(Long id, Long sessionId, Long userId, LocalDateTime createdAt, LocalDateTime updatedAt) {
super(id, createdAt, updatedAt);
this.sessionId = sessionId;
this.userId = userId;
}

public Long getSessionId() {
return sessionId;
}

public Long getUserId() {
return userId;
}
}
41 changes: 38 additions & 3 deletions src/main/java/nextstep/courses/domain/image/CoverImage.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,56 @@
package nextstep.courses.domain.image;

public class CoverImage {
private final long size;
import java.time.LocalDateTime;
import nextstep.core.domain.BaseEntity;

public class CoverImage extends BaseEntity {
private final Long sessionId;
private final Long size;
private final ImageType type;
private final int width;
private final int height;

public CoverImage(long size, ImageType type, int width, int height) {
public CoverImage(Long sessionId, long size, ImageType type, int width, int height) {
this(null, sessionId, size, type, width, height, LocalDateTime.now(), null);
validateSize(size);
validateDimension(width, height);
validateRatio(width, height);
}

public CoverImage(Long id, Long sessionId, long size, ImageType type, int width, int height,
LocalDateTime createdAt, LocalDateTime updatedAt) {
super(id, createdAt, updatedAt);
this.sessionId = sessionId;
this.size = size;
this.type = type;
this.width = width;
this.height = height;
}

public Long getSessionId() {
return sessionId;
}

public Long getSize() {
return size;
}

public ImageType getType() {
return type;
}

public String getTypeName() {
return type.name();
}

public int getWidth() {
return width;
}

public int getHeight() {
return height;
}

private void validateRatio(int width, int height) {
if (width * 2 != height * 3) {
throw new IllegalArgumentException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@ private EnrollmentPolicy(SessionType sessionType, int capacity, long fee) {
this.fee = fee;
}

public SessionType getSessionType() {
return sessionType;
}

public String getSessionTypeName() {
return sessionType.name();
}

public int getCapacity() {
return capacity;
}

public long getFee() {
return fee;
}


public static EnrollmentPolicy free() {
return new EnrollmentPolicy(SessionType.FREE, Integer.MAX_VALUE, 0L);
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/nextstep/courses/domain/session/Period.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ public Period(LocalDate startDate, LocalDate endDate) {
this.endDate = endDate;
}

public LocalDate getStartDate() {
return startDate;
}

public LocalDate getEndDate() {
return endDate;
}

private void validateDateOrder(LocalDate startDate, LocalDate endDate) {
if (startDate.isAfter(endDate)) {
throw new IllegalArgumentException();
Expand Down
74 changes: 65 additions & 9 deletions src/main/java/nextstep/courses/domain/session/Session.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,80 @@
package nextstep.courses.domain.session;

import nextstep.courses.domain.image.CoverImage;
import java.time.LocalDate;
import java.time.LocalDateTime;
import nextstep.core.domain.SoftDeletableBaseEntity;
import nextstep.payments.domain.Payment;
import nextstep.users.domain.NsUser;

public class Session {
private final Students students = new Students();
private final Period period;
private final CoverImage coverImage;
private final SessionStatus sessionStatus;
private final EnrollmentPolicy enrollmentPolicy;
public class Session extends SoftDeletableBaseEntity {
private Long courseId;
private Students students = new Students();
private Period period;
private SessionStatus sessionStatus;
private EnrollmentPolicy enrollmentPolicy;

public Session(Period period, CoverImage coverImage, SessionStatus sessionStatus,
public Session(Long courseId, Period period, SessionStatus sessionStatus,
EnrollmentPolicy enrollmentPolicy) {
this(0L, courseId, period, sessionStatus, enrollmentPolicy, LocalDateTime.now(), null);
}

public Session(Long id, Long courseId, Period period, SessionStatus sessionStatus,
EnrollmentPolicy enrollmentPolicy, LocalDateTime createdAt, LocalDateTime updatedAt) {
super(id, createdAt, updatedAt);
this.courseId = courseId;
this.period = period;
this.coverImage = coverImage;
this.sessionStatus = sessionStatus;
this.enrollmentPolicy = enrollmentPolicy;
}

public Long getCourseId() {
return courseId;
}

public Students getStudents() {
return students;
}

public Period getPeriod() {
return period;
}

public SessionStatus getSessionStatus() {
return sessionStatus;
}

public String getSessionStatusName() {
return sessionStatus.name();
}

public EnrollmentPolicy getEnrollmentPolicy() {
return enrollmentPolicy;
}

public LocalDate getStartDate() {
return period.getStartDate();
}

public LocalDate getEndDate() {
return period.getEndDate();
}

public SessionType getSessionType() {
return enrollmentPolicy.getSessionType();
}

public String getSessionTypeName() {
return enrollmentPolicy.getSessionTypeName();
}

public int getCapacity() {
return enrollmentPolicy.getCapacity();
}

public long getFee() {
return enrollmentPolicy.getFee();
}

public void enroll(NsUser user) {
enroll(user, null);
}
Expand Down
Loading