Skip to content
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

Step3 #358

Open
wants to merge 2 commits into
base: h3yon
Choose a base branch
from
Open

Step3 #358

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
23 changes: 23 additions & 0 deletions src/main/java/nextstep/common/domain/BaseEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package nextstep.common.domain;

import java.time.LocalDateTime;

public class BaseEntity {
protected Long id;
protected LocalDateTime createdAt;
protected LocalDateTime updatedAt;

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

public Long getId() {
return this.id;
}

public LocalDateTime getCreatedAt() {
return this.createdAt;
}
}
20 changes: 20 additions & 0 deletions src/main/java/nextstep/common/utils/DateTimeUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package nextstep.common.utils;

import java.sql.Timestamp;
import java.time.LocalDateTime;

public class DateTimeUtils {
public static Timestamp toTimeStamp(LocalDateTime localDateTime) {
if (localDateTime == null) {
return null;
}
return Timestamp.valueOf(localDateTime);
}

public static LocalDateTime toLocalDateTime(Timestamp timestamp) {
if (timestamp == null) {
return null;
}
return timestamp.toLocalDateTime();
}
}
18 changes: 3 additions & 15 deletions src/main/java/nextstep/courses/domain/Course.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
package nextstep.courses.domain;

import nextstep.common.domain.BaseEntity;
import nextstep.courses.domain.session.Session;

import java.time.LocalDateTime;
import java.util.List;

public class Course {
public class Course extends BaseEntity {
private Long id;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idBaseEntity에 있으니 제거해도 괜찮지 않을까요?


private String title;

private Long creatorId;

private LocalDateTime createdAt;

private LocalDateTime updatedAt;
private List<Session> sessions;

public Course() {
}

public Course(String title, Long creatorId) {
this(0L, title, creatorId, LocalDateTime.now(), null, null);
}
Expand All @@ -28,11 +22,9 @@ public Course(Long id, String title, Long creatorId, LocalDateTime createdAt, Lo
this(0L, title, creatorId, createdAt, updatedAt, null);
}
public Course(Long id, String title, Long creatorId, LocalDateTime createdAt, LocalDateTime updatedAt, List<Session> sessions) {
this.id = id;
super(id, createdAt, updatedAt);
this.title = title;
this.creatorId = creatorId;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
this.sessions = sessions;
}

Expand All @@ -44,10 +36,6 @@ public Long getCreatorId() {
return creatorId;
}

public LocalDateTime getCreatedAt() {
return createdAt;
}

@Override
public String toString() {
return "Course{" +
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/nextstep/courses/domain/CourseRepository.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package nextstep.courses.domain;

import java.util.Optional;

public interface CourseRepository {
int save(Course course);
long save(Course course);

Course findById(Long id);
Optional<Course> findById(Long id);
}
35 changes: 26 additions & 9 deletions src/main/java/nextstep/courses/domain/Enrollment.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
package nextstep.courses.domain;

public class Enrollment{
private Long id;
private Long nsUserId;
private Long sessionId;

public Enrollment(final Long nsUserId, final Long sessionId) {
this.nsUserId = nsUserId;
this.sessionId = sessionId;
}
import nextstep.common.domain.BaseEntity;

import java.time.LocalDateTime;

public class Enrollment extends BaseEntity {
private Long nsUserId;
private Long sessionId;


public Enrollment(final Long nsUserId, final Long sessionId) {
this(null, nsUserId, sessionId, LocalDateTime.now(), null);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

생성자 내부에서 생성일시를 만들지 말고, 서비스 또는 외부에서 시간을 요청 받아보면 어떨까요?
현재의 구조에서는 한 트랜잭션 내부에서 여러 데이터를 생성하더라도, 각 데이터의 생성 일시가 달라질 것으로 보입니다.

}

public Enrollment(final Long id, final Long nsUserId, final Long sessionId, LocalDateTime createAt, LocalDateTime updatedAt) {
super(id, createAt, updatedAt);
this.nsUserId = nsUserId;
this.sessionId = sessionId;
}

public Long nsUserId() {
return nsUserId;
}

public Long sessionId() {
return sessionId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package nextstep.courses.domain;

import java.util.Optional;

public interface EnrollmentRepository {
long save(Enrollment enrollment);

Optional<Enrollment> findById(Long id);
}
35 changes: 32 additions & 3 deletions src/main/java/nextstep/courses/domain/image/CoverImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,26 @@ public class CoverImage {
private static final int MIN_WIDTH = 300;
private static final int MIN_HEIGHT = 200;
private static final Long MAX_SIZE = 1024L * 1024L;
private static final int WIDTH_RATIO = 3;
private static final int HEIGHT_RATIO = 2;
private final Long id;

private final int width;
private final int height;
private final long size;
private final ImageType imageType;

public CoverImage(final long size, final int width, final int height, final ImageType imageType) {

public CoverImage(int width, int height, long size, ImageType imageType) {
this(null, width, height, size, imageType);
}

public CoverImage(Long id, int width, int height, long size, ImageType imageType) {
validateImage(size, width, height);
this.size = size;
this.id = id;
this.width = width;
this.height = height;
this.size = size;
this.imageType = imageType;
}

Expand All @@ -35,7 +44,7 @@ private void validateSize(final long size) {
}

private void validateRatio(final int width, final int height) {
if (width * 2 != height * 3) {
if (width * HEIGHT_RATIO != height * WIDTH_RATIO) {
throw new IllegalArgumentException(INVALID_IMAGE_RATIO_MESSAGE);
}
}
Expand All @@ -45,4 +54,24 @@ private void validatePixel(final int width, final int height) {
throw new IllegalArgumentException(INVALID_IMAGE_PIXEL_MESSAGE);
}
}

public int getWidth() {
return width;
}

public int getHeight() {
return height;
}

public long getSize() {
return size;
}

public ImageType getImageType() {
return imageType;
}

public Long getId() {
return id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package nextstep.courses.domain.image;

import java.util.Optional;

public interface ImageRepository {
long save(CoverImage coverImage);

Optional<CoverImage> findById(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

public class EnrollmentCount {
private int availableCount;
private int remainCount;

public EnrollmentCount(final int availableCount) {
this.availableCount = availableCount;
this.remainCount = availableCount;
}

public boolean isNoRemaining() {
return remainCount <= 0;
return availableCount < 1;
}

public void decrease() {
this.remainCount--;
this.availableCount--;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

availableCount이 총 수강 가능한 인원이라면 변하면 안 될 것 같아요. 원래 강의의 최대 수강 인원이 몇 명인지는 유지되어야 하지 않을까요?
remainCount와 수강 인원(Enrollment)가 중복이라서, remainCount 없이 Enrollment를 이용해도 되지 않을지 궁금해서 남긴 코멘트였습니다. :)

}

public int getAvailableCount() {
return availableCount;
}
}
16 changes: 0 additions & 16 deletions src/main/java/nextstep/courses/domain/session/FreeSession.java

This file was deleted.

33 changes: 0 additions & 33 deletions src/main/java/nextstep/courses/domain/session/PaidSession.java

This file was deleted.

Loading