-
Notifications
You must be signed in to change notification settings - Fork 247
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
Step2 - 도메인설계 #486
base: boy0516
Are you sure you want to change the base?
Step2 - 도메인설계 #486
Changes from all commits
c162962
888cd73
c4a02d5
1733405
779d0b4
eb7176f
83e6f7d
bb0bfd5
d861761
4ca57bb
ab2f1d3
d3955c8
e36ee82
c98993c
6a88dd8
c424dda
5cf8354
5f95b2c
65fb92a
d444e6f
83fc5b2
3664a26
7c0f36e
741d0ae
40dd2b8
5b1791d
72a6a15
4c9da8c
906b38c
e6a9287
08f4a51
42a7a8b
4eda457
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,9 @@ | ||
package nextstep.courses.domain; | ||
|
||
public class FreeSession { | ||
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 final Session session; | ||
|
||
public FreeSession(Session session) { | ||
this.session = session; | ||
} | ||
Comment on lines
+3
to
+8
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. 이걸 따로 만든 이유가 있나요? |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package nextstep.courses.domain; | ||
|
||
public class Image { | ||
|
||
private ImageType imageType; | ||
private ImageSize imageSize; | ||
private ImageRate imageRate; | ||
|
||
public Image() { | ||
} | ||
|
||
public Image(ImageType imageType, ImageSize imageSize, ImageRate imageRate) { | ||
this.imageType = imageType; | ||
this.imageSize = imageSize; | ||
this.imageRate = imageRate; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,30 @@ | ||||||
package nextstep.courses.domain; | ||||||
|
||||||
public class ImageRate { | ||||||
|
||||||
private final int MIN_WIDTH_SIZE = 300; | ||||||
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.
Suggested change
|
||||||
public int width; | ||||||
public int height; | ||||||
|
||||||
public ImageRate(int width, int height) { | ||||||
validRate(width, height); | ||||||
validPixelSize(width); | ||||||
this.width = width; | ||||||
this.height = height; | ||||||
} | ||||||
|
||||||
private void validRate(int width, int height) { | ||||||
if (width / height != 3 / 2) { | ||||||
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. 3/2도 상수화를 해두면 어떨까요? |
||||||
throw new IllegalArgumentException("이미지 width, height 비율이 3:2를 만족하지 않습니다"); | ||||||
} | ||||||
} | ||||||
|
||||||
private void validPixelSize(int width) { | ||||||
if (width < MIN_WIDTH_SIZE) { | ||||||
throw new IllegalArgumentException("이미지 width가 300px 보다 작습니다"); | ||||||
} | ||||||
} | ||||||
|
||||||
|
||||||
|
||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package nextstep.courses.domain; | ||
|
||
public class ImageSize { | ||
|
||
private final int MAX_SIZE = 1; | ||
|
||
private int size; | ||
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. 이 size의 용량을 MB로 설정하셨군요. |
||
|
||
public ImageSize(int size) { | ||
validSize(size); | ||
this.size = size; | ||
} | ||
|
||
private void validSize(int size) { | ||
if (size > MAX_SIZE) { | ||
throw new IllegalArgumentException("이미지 사이즈가 1MB를 초과했습니다: " + size + "MB"); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package nextstep.courses.domain; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public enum ImageType { | ||
|
||
GIF(List.of("gif")), | ||
JPG(List.of("jpg", "jpeg")), | ||
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. 굳이 List로 하지 않고 분리하는게 더 깔끔할거 같아요! |
||
PNG(List.of("png")), | ||
SVG(List.of("svg")); | ||
|
||
private List<String> contentType; | ||
|
||
ImageType(List<String> contentType) { | ||
this.contentType = contentType; | ||
} | ||
|
||
public static boolean isValidType(String type) { | ||
return Arrays.stream(ImageType.values()) | ||
.filter(imageType -> imageType.isContain(type)) | ||
.findAny() | ||
.isPresent(); | ||
} | ||
|
||
private boolean isContain(String type) { | ||
return this.contentType.contains(type); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package nextstep.courses.domain; | ||
|
||
import nextstep.payments.domain.Payment; | ||
import nextstep.users.domain.NsUser; | ||
|
||
public class JoinUser { | ||
|
||
private final NsUser user; | ||
private final Payment payment; | ||
|
||
public JoinUser(NsUser user, Payment payment) { | ||
this.user = user; | ||
this.payment = payment; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package nextstep.courses.domain; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class JoinUsers { | ||
|
||
private final List<JoinUser> joinUsers; | ||
|
||
public JoinUsers(List<JoinUser> joinUsers) { | ||
|
||
this.joinUsers = joinUsers; | ||
} | ||
|
||
public void add(JoinUser joinUser) { | ||
this.joinUsers.add(joinUser); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
JoinUsers joinUsers1 = (JoinUsers) o; | ||
return Objects.equals(joinUsers, joinUsers1.joinUsers); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(joinUsers); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package nextstep.courses.domain; | ||
|
||
import java.util.Objects; | ||
|
||
import nextstep.payments.domain.Payment; | ||
|
||
public class PaySession { | ||
|
||
private final Session session; | ||
private int joinLimit; | ||
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 PaySession(Session session) { | ||
this.session = session; | ||
} | ||
|
||
public void join(JoinUser joinUser, Payment payment) { | ||
validPaid(payment); | ||
session.join(joinUser); | ||
} | ||
|
||
private void validPaid(Payment payment) { | ||
if(!payment.isPaid()) | ||
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. 실제 강의엔 수강료가 있고 그 수강료 만큼 가격을 내야 하지 않을까요? 유료 강의는 수강생이 결제한 금액과 수강료가 일치할 때 수강 신청이 가능하다. |
||
throw new IllegalStateException("유료 강의의 지불이 완료되지 않았습니다."); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
PaySession session1 = (PaySession) o; | ||
return Objects.equals(session, session1.session); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(session); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package nextstep.courses.domain; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class Period { | ||
|
||
private final LocalDateTime startDate; | ||
private final LocalDateTime endDate; | ||
|
||
public Period() { | ||
this(LocalDateTime.now(), LocalDateTime.now().plusWeeks(1)); | ||
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 Period(LocalDateTime startDate, LocalDateTime endDate) { | ||
this.startDate = startDate; | ||
this.endDate = endDate; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package nextstep.courses.domain; | ||
|
||
import java.util.*; | ||
|
||
public class Session { | ||
|
||
private final JoinUsers joinUsers; | ||
private final Image coverImage; | ||
private final SessionStatus status; | ||
private final Period period; | ||
|
||
public Session() { | ||
this(new ArrayList<>()); | ||
} | ||
|
||
public Session(List<JoinUser> joinUsers) { | ||
this.joinUsers = new JoinUsers(joinUsers); | ||
this.coverImage = new Image(); | ||
this.status = SessionStatus.RECRUITING; | ||
this.period = new Period(); | ||
} | ||
|
||
public void join(JoinUser joinUser) { | ||
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. 강의 수강신청은 강의 상태가 모집중일 때만 가능하다. 이것도 필요하지 않을까요? |
||
validRecruiting(); | ||
joinUsers.add(joinUser); | ||
} | ||
|
||
private void validRecruiting() { | ||
if (!status.isRecruiting()) { | ||
throw new IllegalStateException("강의가 모집중이 아닙니다"); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Session session = (Session) o; | ||
return Objects.equals(joinUsers, session.joinUsers); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(joinUsers); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package nextstep.courses.domain; | ||
|
||
public enum SessionStatus { | ||
READY, | ||
RECRUITING, | ||
END; | ||
|
||
public boolean isRecruiting() { | ||
return this == RECRUITING; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package nextstep.courses.domain; | ||
|
||
public enum SessionType { | ||
PAY(), | ||
FREE() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package nextstep.courses.domain; | ||
|
||
import java.util.List; | ||
|
||
public class Sessions { | ||
|
||
private List<Session> sessions; | ||
|
||
} |
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.
과정이 기수별로 있다. 라는것은 과정 == Course // 기수 == Session으로
에를들어 현재 듣고 계신 TDD 과정이 있고 1기~18기까지가 있었죠.
즉, 1개의 Course에 여러개의 Session이 잇어야 할거 같습니다.