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

Step2 - 도메인설계 #486

Open
wants to merge 33 commits into
base: boy0516
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c162962
docs: 수강 신청 기능 개발 목록 문서화
boy0516 Apr 6, 2024
888cd73
docs: 수강 신청 기능 개발 목록 문서화
boy0516 Apr 7, 2024
c4a02d5
test: 이미지 비율 테스트 코드
boy0516 Apr 7, 2024
1733405
feat: 이미지 비율 클래스 생성
boy0516 Apr 7, 2024
779d0b4
test: 이미지 비율 검증 테스트 수정
boy0516 Apr 7, 2024
eb7176f
test: 이미지 사이즈 검증 테스트
boy0516 Apr 7, 2024
83e6f7d
feat: 이미지 사이즈 클래스, 검증 추가
boy0516 Apr 7, 2024
bb0bfd5
docs: 구현목록 체크
boy0516 Apr 7, 2024
d861761
feat: 이미지 타입 enum 생성
boy0516 Apr 7, 2024
4ca57bb
test: 이미지 가로 픽셀 검증 테스트
boy0516 Apr 7, 2024
ab2f1d3
feat: 이미지 가로 픽셀 검증 추가
boy0516 Apr 7, 2024
d3955c8
docs: 구현목록 체크
boy0516 Apr 7, 2024
e36ee82
feat: 강의 타입 enum 추가
boy0516 Apr 7, 2024
c98993c
refactor: 네이밍 Lecture -> Session
boy0516 Apr 7, 2024
6a88dd8
feat: 강의 상태 enum 추가
boy0516 Apr 7, 2024
c424dda
test: 수강 신청 테스트 추가
boy0516 Apr 7, 2024
5cf8354
feat: 강의 수강신청 구현
boy0516 Apr 7, 2024
5f95b2c
docs: 수강생, 결제 검증 구현 추가
boy0516 Apr 7, 2024
65fb92a
test: 신청 사용자 테스트 코드 추가
boy0516 Apr 7, 2024
d444e6f
feat: JoinUser 클래스 생성
boy0516 Apr 7, 2024
83fc5b2
test: Session 수강신청 테스트 수정
boy0516 Apr 7, 2024
3664a26
feat: joinUesrs 일급컬렉션 추가
boy0516 Apr 7, 2024
7c0f36e
feat: joinUesrs 일급컬렉션 추가
boy0516 Apr 14, 2024
741d0ae
feat: SessionStatus 추가
boy0516 Apr 14, 2024
40dd2b8
feat: 유료강의 추가
boy0516 Apr 14, 2024
5b1791d
feat: 결제 관련 코드 추가
boy0516 Apr 14, 2024
72a6a15
feat: 결제 관련 테스트 클래스 추가
boy0516 Apr 14, 2024
4c9da8c
feat: 이미지, 이미지 타입 추가
boy0516 Apr 14, 2024
906b38c
test: 이미지 관련 테스트 코드 수정
boy0516 Apr 14, 2024
e6a9287
feat: 강의 일급컬렉션 추가 및 시작일 종료일 추가
boy0516 Apr 14, 2024
08f4a51
docs: 구현 목록 수정
boy0516 Apr 14, 2024
42a7a8b
fix: 1단계 피드백 반영
boy0516 Apr 14, 2024
4eda457
test: Answers 테스트 코드 추가 및 관련 코드 수정
boy0516 Apr 14, 2024
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
38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,38 @@
* [텍스트와 이미지로 살펴보는 온라인 코드 리뷰 과정](https://github.com/next-step/nextstep-docs/tree/master/codereview)

# todo
- [] Question 에 삭제 상태 변경 추가
- [] Answer에 삭제 상태 변경 추가
- [] Answer 일급컬렉션 추가
- [x] Question 에 삭제 상태 변경 추가
- [x] Answer에 삭제 상태 변경 추가
- [x] Answer 일급컬렉션 추가

# todo
### 수강신청
- 과정
- [] 강의 수강신청
- 강의
- 시작일
- 종료일
- 커버 이미지
- 이미지 크기
- [X] 1MB 이하 허용 검증
- 이미지 타입
- [X] gif, jpg(jpeg 포함), png, svg만 허용
- 이미지 비율
- width
- [X] 300px 이상 값 검증
- height
- [X] width, heigth 비율 3:2 검증
- 강의타입(유료, 무료)
- 유료 강의
- 유료 강의 최대 수강 인원 제한 검증
- [] 유료 강의 최대 수강 인원 초과 검증.
- 무료 강의
- 무료 강의 최대 수강 인원 무제한
- 강의 상태(준비중, 모집중, 종료)
- [x] 강의 수강신청
- [X] 강의 상태가 준비중 검증
- 수강생 일급컬렉션
- 수강생
- 결제금액
- 결제
- [X] 결제 여부 검증
5 changes: 2 additions & 3 deletions src/main/java/nextstep/courses/domain/Course.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ public class Course {

private Long creatorId;

private Sessions sessions;

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이 잇어야 할거 같습니다.


private LocalDateTime createdAt;

private LocalDateTime updatedAt;

public Course() {
}

public Course(String title, Long creatorId) {
this(0L, title, creatorId, LocalDateTime.now(), null);
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/nextstep/courses/domain/FreeSession.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package nextstep.courses.domain;

public class FreeSession {

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

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

이걸 따로 만든 이유가 있나요?
유료와 무료를 나눠서 객체를 관리하고 싶다면 조합보단 상속이 더 어울리는 형태가 아닐까 생각이 들어요.

}
18 changes: 18 additions & 0 deletions src/main/java/nextstep/courses/domain/Image.java
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;
}

}
30 changes: 30 additions & 0 deletions src/main/java/nextstep/courses/domain/ImageRate.java
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;

Choose a reason for hiding this comment

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

Suggested change
private final int MIN_WIDTH_SIZE = 300;
private static final int MIN_WIDTH_SIZE = 300;

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) {

Choose a reason for hiding this comment

The 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 보다 작습니다");
}
}



}
19 changes: 19 additions & 0 deletions src/main/java/nextstep/courses/domain/ImageSize.java
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;

Choose a reason for hiding this comment

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

이 size의 용량을 MB로 설정하셨군요.
기본적으로 어떤 용량으로 설정하는지 한번 고민해보면 좋을거 같습니다.
예를들어 S3는 용량을 default가 무엇일까요?
혹은 서버에 저장할때.


public ImageSize(int size) {
validSize(size);
this.size = size;
}

private void validSize(int size) {
if (size > MAX_SIZE) {
throw new IllegalArgumentException("이미지 사이즈가 1MB를 초과했습니다: " + size + "MB");
}
}
}
29 changes: 29 additions & 0 deletions src/main/java/nextstep/courses/domain/ImageType.java
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")),

Choose a reason for hiding this comment

The 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);
}
}
15 changes: 15 additions & 0 deletions src/main/java/nextstep/courses/domain/JoinUser.java
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;
}
}
35 changes: 35 additions & 0 deletions src/main/java/nextstep/courses/domain/JoinUsers.java
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);
}
}
42 changes: 42 additions & 0 deletions src/main/java/nextstep/courses/domain/PaySession.java
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;

Choose a reason for hiding this comment

The 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())

Choose a reason for hiding this comment

The 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);
}
}
18 changes: 18 additions & 0 deletions src/main/java/nextstep/courses/domain/Period.java
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));

Choose a reason for hiding this comment

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

무조건 기간은 일주일인가요?

}

public Period(LocalDateTime startDate, LocalDateTime endDate) {
this.startDate = startDate;
this.endDate = endDate;
}
}
50 changes: 50 additions & 0 deletions src/main/java/nextstep/courses/domain/Session.java
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) {

Choose a reason for hiding this comment

The 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);
}
}
11 changes: 11 additions & 0 deletions src/main/java/nextstep/courses/domain/SessionStatus.java
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;
}
}
6 changes: 6 additions & 0 deletions src/main/java/nextstep/courses/domain/SessionType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package nextstep.courses.domain;

public enum SessionType {
PAY(),
FREE()
}
9 changes: 9 additions & 0 deletions src/main/java/nextstep/courses/domain/Sessions.java
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;

}
4 changes: 4 additions & 0 deletions src/main/java/nextstep/payments/domain/Payment.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ public Payment(String id, Long sessionId, Long nsUserId, Long amount) {
this.amount = amount;
this.createdAt = LocalDateTime.now();
}

public boolean isPaid() {
return true;
}
}
Loading