-
Notifications
You must be signed in to change notification settings - Fork 309
Step2 리뷰요청 드립니다. #819
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
Merged
Merged
Step2 리뷰요청 드립니다. #819
Changes from 10 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e900a4a
feat: CoverImage -> ImageType 구현
qwer920414-ctrl 8271411
feat: CoverImage -> ImageSize 구현
qwer920414-ctrl cdcc5a9
feat: CoverImage -> ImageDimension 구현
qwer920414-ctrl 20eb67f
feat: Session -> SessionDuration(시작일자/종료일자) 구현
qwer920414-ctrl 2ae44f9
feat: Session -> SessionState 구현
qwer920414-ctrl 31bccd9
feat: Session -> EnrollmentPolicy 인터페이스 구현 -> FreeEnrollmentPolicy(무료)
qwer920414-ctrl 7131ea4
feat: Session -> EnrollmentPolicy 인터페이스 구현 -> PaidEnrollmentPolicy(유료…
qwer920414-ctrl 00c2257
feat: Session 필드 추가
qwer920414-ctrl 3612e77
feat: Session -> CoverImage 클래스 생성자 추가
qwer920414-ctrl b9e6e97
feat: Session 기본 생성자 추가
qwer920414-ctrl 770df4d
feat: CoverImage -> ImageType에 fileName 추가
qwer920414-ctrl 7dd2e8c
test: PaidEnrollmentPolicy 테스트코드 추가
qwer920414-ctrl bfc3ef3
feat: Session - 등록 로직 작성
qwer920414-ctrl 64113eb
feat: Course - Session 추가(List<Session> -> Sessions 일급컬렉션 생성)
qwer920414-ctrl 8f24ee3
feat: Enrollments 일급컬렉션 추가
qwer920414-ctrl 91257e4
refactor: Capacity 역할 이동
qwer920414-ctrl b93d1f4
fix: Capacity 로직 수정
qwer920414-ctrl c97f057
refactor: Session Enrollments 적용 & SessionTest(Builder 적용 시도)
qwer920414-ctrl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| public class Capacity { | ||
|
|
||
| private int max; | ||
| private int current; | ||
|
|
||
| public Capacity(int max, int current) { | ||
| this.max = max; | ||
| this.current = current; | ||
| } | ||
|
|
||
| public void validateAvailable() { | ||
| if (current > max) { | ||
| throw new IllegalStateException(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| public class CoverImage { | ||
| private ImageSize imageSize; | ||
| private ImageType imageType; | ||
| private ImageDimension imageDimension; | ||
|
|
||
| public CoverImage(int size, ImageType imageType, int width, int height) { | ||
| this(new ImageSize(size), imageType, new ImageDimension(width, height)); | ||
| } | ||
|
|
||
| public CoverImage(ImageSize imageSize, ImageType imageType, ImageDimension imageDimension) { | ||
| this.imageSize = imageSize; | ||
| this.imageType = imageType; | ||
| this.imageDimension = imageDimension; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| import nextstep.payments.domain.Payment; | ||
|
|
||
| public interface EnrollmentPolicy { | ||
| void validateEnrollment(Payment payment); | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
src/main/java/nextstep/courses/domain/FreeEnrollmentPolicy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| import nextstep.payments.domain.Payment; | ||
|
|
||
| public class FreeEnrollmentPolicy implements EnrollmentPolicy{ | ||
| @Override | ||
| public void validateEnrollment(Payment payment) { | ||
| // 무료강의는 검증하지 않는다 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| public class ImageDimension { | ||
|
|
||
| public static final int HEIGHT_RATIO = 2; | ||
| public static final int WIDTH_RATIO = 3; | ||
| public static final int MIN_WIDTH = 300; | ||
| public static final int MIN_HEIGHT = 200; | ||
| private int width; | ||
| private int height; | ||
|
|
||
| public ImageDimension(int width, int height) { | ||
| validateMinimumSize(width, height); | ||
| validateRatio(width, height); | ||
| this.width = width; | ||
| this.height = height; | ||
| } | ||
|
|
||
| private static void validateMinimumSize(int width, int height) { | ||
| if (width < MIN_WIDTH || height < MIN_HEIGHT) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
|
|
||
| private static void validateRatio(int width, int height) { | ||
| if (!(HEIGHT_RATIO * width == WIDTH_RATIO * height)) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class ImageSize { | ||
|
|
||
| public static final int MAX_SIZE = 1_048_576; | ||
| private int imageSize; | ||
|
|
||
| public ImageSize(int imageSize) { | ||
| if (imageSize > MAX_SIZE) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| this.imageSize = imageSize; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object object) { | ||
| if (this == object) return true; | ||
| if (object == null || getClass() != object.getClass()) return false; | ||
| ImageSize imageSize1 = (ImageSize) object; | ||
| return imageSize == imageSize1.imageSize; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hashCode(imageSize); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| public enum ImageType { | ||
|
|
||
| GIF("gif"), | ||
| JPG("jpg", "jpeg"), | ||
| PNG("png"), | ||
| SVG("svg"); | ||
|
|
||
| private final String[] extensions; | ||
|
|
||
| ImageType(String... extensions) { | ||
| this.extensions = extensions; | ||
| } | ||
|
|
||
| private boolean matches(String extension) { | ||
| return Arrays.stream(extensions) | ||
| .anyMatch(ext -> ext.equalsIgnoreCase(extension)); | ||
| } | ||
|
|
||
| public static ImageType from(String extension) { | ||
| return Arrays.stream(values()) | ||
| .filter(type -> type.matches(extension)) | ||
| .findFirst() | ||
| .orElseThrow(() -> new IllegalArgumentException()); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class Money { | ||
| private final long amount; | ||
|
|
||
| public Money(long amount) { | ||
| this.amount = amount; | ||
| } | ||
|
|
||
| public boolean isEqualTo(Money other) { | ||
| return this.equals(other); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object object) { | ||
| if (this == object) return true; | ||
| if (object == null || getClass() != object.getClass()) return false; | ||
| Money money = (Money) object; | ||
| return amount == money.amount; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hashCode(amount); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/main/java/nextstep/courses/domain/PaidEnrollmentPolicy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| import nextstep.payments.domain.Payment; | ||
|
|
||
| public class PaidEnrollmentPolicy implements EnrollmentPolicy { | ||
|
|
||
| private final Money money; | ||
| private final Capacity capacity; | ||
|
|
||
| public PaidEnrollmentPolicy(Money money, Capacity capacity) { | ||
| this.money = money; | ||
| this.capacity = capacity; | ||
| } | ||
|
|
||
| @Override | ||
| public void validateEnrollment(Payment payment) { | ||
| capacity.validateAvailable(); | ||
| validatePayment(payment); | ||
| } | ||
|
|
||
| private void validatePayment(Payment payment) { | ||
| if (!payment.isSameAmount(money)) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| import nextstep.payments.domain.Payment; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public class Session { | ||
| private final long id; | ||
| private final SessionDuration sessionDuration; | ||
| private final CoverImage coverImage; | ||
| private final EnrollmentPolicy enrollmentPolicy; | ||
| private final SessionState sessionState; | ||
|
|
||
| public Session(long id | ||
| , LocalDateTime startDate | ||
| , LocalDateTime endDate | ||
| , int size | ||
| , ImageType imageType | ||
| , int width | ||
| , int height | ||
| , EnrollmentPolicy enrollmentPolicy | ||
| , SessionState sessionState) { | ||
| this(id, new SessionDuration(startDate, endDate), new CoverImage(size, imageType, width, height) | ||
| , enrollmentPolicy, sessionState); | ||
| } | ||
|
|
||
| public Session(long id, SessionDuration sessionDuration, CoverImage coverImage | ||
| , EnrollmentPolicy enrollmentPolicy, SessionState sessionState) { | ||
| this.id = id; | ||
| this.sessionDuration = sessionDuration; | ||
| this.coverImage = coverImage; | ||
| this.enrollmentPolicy = enrollmentPolicy; | ||
| this.sessionState = sessionState; | ||
| } | ||
|
|
||
| public void enroll() { | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/main/java/nextstep/courses/domain/SessionDuration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public class SessionDuration { | ||
| private LocalDateTime startDate; | ||
| private LocalDateTime endDate; | ||
|
|
||
| public SessionDuration(LocalDateTime startDate, LocalDateTime endDate) { | ||
| validateDate(startDate, endDate); | ||
| this.startDate = startDate; | ||
| this.endDate = endDate; | ||
| } | ||
|
|
||
| private void validateDate(LocalDateTime startDate, LocalDateTime endDate) { | ||
| if (!startDate.isBefore(endDate)) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| public enum SessionState { | ||
| READY, | ||
| OPEN, | ||
| CLOSED; | ||
|
|
||
| public void validateEnroll() { | ||
| if (this != OPEN) { | ||
| throw new IllegalStateException(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
|
||
| class CapacityTest { | ||
|
|
||
| @Test | ||
| @DisplayName("최대 인원을 넘어서 수강신청이 들어오면 Exceptionn") | ||
| void max() { | ||
| Capacity capacity = new Capacity(300, 301); | ||
| assertThatThrownBy(() -> capacity.validateAvailable()) | ||
| .isInstanceOf(IllegalStateException.class); | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/test/java/nextstep/courses/domain/ImageDimensionTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package nextstep.courses.domain; | ||
|
|
||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThatNoException; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
|
||
| class ImageDimensionTest { | ||
|
|
||
| @Test | ||
| @DisplayName("width가 300px 미만이면 예외가 발생한다") | ||
| void create_width_exception() { | ||
| assertThatThrownBy(() -> new ImageDimension(299, 200)) | ||
| .isInstanceOf(IllegalArgumentException.class); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("height가 200px 미만이면 예외가 발생한다") | ||
| void create_height_exception() { | ||
| assertThatThrownBy(() -> new ImageDimension(300, 199)) | ||
| .isInstanceOf(IllegalArgumentException.class); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("width와 height는 3:2 비율이 아니면 예외가 발생한다") | ||
| void create_width_height_exception() { | ||
| assertThatThrownBy(() -> new ImageDimension(300, 300)) | ||
| .isInstanceOf(IllegalArgumentException.class); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("width_height_정상생성") | ||
| void create_success() { | ||
| assertThatNoException() | ||
| .isThrownBy(() -> new ImageDimension(300, 200)); | ||
|
|
||
| assertThatNoException() | ||
| .isThrownBy(() -> new ImageDimension(600, 400)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
👍