-
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
Step3 #358
base: h3yon
Are you sure you want to change the base?
Step3 #358
Changes from all commits
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,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; | ||
} | ||
} |
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(); | ||
} | ||
} |
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); | ||
} |
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); | ||
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. 생성자 내부에서 생성일시를 만들지 말고, 서비스 또는 외부에서 시간을 요청 받아보면 어떨까요? |
||
} | ||
|
||
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); | ||
} |
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 |
---|---|---|
|
@@ -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--; | ||
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.
|
||
} | ||
|
||
public int getAvailableCount() { | ||
return availableCount; | ||
} | ||
} |
This file was deleted.
This file was deleted.
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.
id
가BaseEntity
에 있으니 제거해도 괜찮지 않을까요?