-
Notifications
You must be signed in to change notification settings - Fork 300
π 2λ¨κ³ - μκ°μ μ²(λλ©μΈ λͺ¨λΈ) #715
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
base: wlwpfh
Are you sure you want to change the base?
Changes from all commits
67d8c98
69f7da0
eafe229
b981844
101a978
c26c840
62b1673
eb4aecd
1acc6f1
eeeae90
5a0bb9f
d8f480f
f249b5d
1b7b8ab
460de6b
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,7 @@ | ||
package nextstep.courses; | ||
|
||
public class CannotEnrollException extends RuntimeException { | ||
public CannotEnrollException(String message) { | ||
super(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package nextstep.courses; | ||
|
||
public class InvalidImageException extends RuntimeException { | ||
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. λ¨μν λ©μμ§λ§ λ°λκ²μ΄λΌλ©΄, 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. νμ¬ λλ©μΈλ³λ‘ custom exceptionμΌλ‘ μμΈμ²λ¦¬λ₯Ό νμ¬ μ΄μ κ°κ² μ§ννμμ΅λλ€..! |
||
public InvalidImageException(String message) { | ||
super(message); | ||
} | ||
|
||
public InvalidImageException(){ | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package nextstep.courses.domain; | ||
package nextstep.courses.domain.course; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package nextstep.courses.domain.session; | ||
|
||
import nextstep.users.domain.NsUser; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class Enrollment { | ||
private final List<NsUser> users; | ||
private final SessionCapacity sessionCapacity; | ||
|
||
public Enrollment(List<NsUser> users, SessionCapacity sessionCapacity) { | ||
this.users = users; | ||
this.sessionCapacity = sessionCapacity; | ||
} | ||
|
||
public Enrollment(SessionCapacity sessionCapacity) { | ||
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. PRμμ²μ μ¬μ©νμ§ μλ λ©μλλ κ³Όκ°ν μ κ±°νλκ²μ΄ μ’λ€κ³ μκ°ν©λλ€. |
||
this(new ArrayList<>(), sessionCapacity); | ||
} | ||
|
||
public Enrollment(int capacity) { | ||
this(new ArrayList<>(), new SessionCapacity(capacity)); | ||
} | ||
|
||
public Enrollment(List<NsUser> users) { | ||
this(users, new SessionCapacity(0)); | ||
} | ||
|
||
public void enroll(NsUser user) { | ||
sessionCapacity.increase(); | ||
this.users.add(user); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(users); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (object == this) { | ||
return true; | ||
} | ||
if (object == null || getClass() != object.getClass()) { | ||
return false; | ||
} | ||
Enrollment enrollment = (Enrollment) object; | ||
return Objects.equals(enrollment.users, this.users); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,43 @@ | ||||||
package nextstep.courses.domain.session; | ||||||
|
||||||
import nextstep.courses.CannotEnrollException; | ||||||
import nextstep.courses.strategy.PaymentStrategy; | ||||||
import nextstep.payments.domain.Payment; | ||||||
import nextstep.users.domain.NsUser; | ||||||
|
||||||
import java.time.LocalDate; | ||||||
|
||||||
public class Session { | ||||||
private final SessionImage image; | ||||||
private final SessionDate date; | ||||||
private final SessionState state; | ||||||
private final Enrollment enrollment; | ||||||
private final PaymentStrategy paymentStrategy; | ||||||
|
||||||
public Session(SessionImage image, SessionDate date, SessionState state, Enrollment enrollment, PaymentStrategy paymentStrategy) { | ||||||
this.image = image; | ||||||
this.date = date; | ||||||
this.state = state; | ||||||
this.enrollment = enrollment; | ||||||
this.paymentStrategy = paymentStrategy; | ||||||
} | ||||||
|
||||||
public void applySession(NsUser user, LocalDate enrollDate, Payment payment) { | ||||||
if (!canApply(enrollDate, payment)) { | ||||||
throw new CannotEnrollException("λ±λ‘ λΆκ°λ₯ν μνμ λλ€."); | ||||||
} | ||||||
this.enrollment.enroll(user); | ||||||
} | ||||||
|
||||||
private boolean canApply(LocalDate enrollDate, Payment payment) { | ||||||
if (!state.canRecruit()) { | ||||||
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
|
||||||
return false; | ||||||
} | ||||||
|
||||||
if (!date.isBefore(enrollDate)) { | ||||||
return false; | ||||||
} | ||||||
|
||||||
return paymentStrategy.payable(payment); | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,57 @@ | ||||||||||||||||||
package nextstep.courses.domain.session; | ||||||||||||||||||
|
||||||||||||||||||
import nextstep.courses.CannotEnrollException; | ||||||||||||||||||
|
||||||||||||||||||
import java.util.Objects; | ||||||||||||||||||
|
||||||||||||||||||
public class SessionCapacity { | ||||||||||||||||||
private static final int MIN_CAPACITY = 1; | ||||||||||||||||||
|
||||||||||||||||||
private int capacity; | ||||||||||||||||||
private final int maxCapacity; | ||||||||||||||||||
|
||||||||||||||||||
public SessionCapacity(int capacity, int maxCapacity) { | ||||||||||||||||||
this.capacity = capacity; | ||||||||||||||||||
this.maxCapacity = maxCapacity; | ||||||||||||||||||
checkValidCapacity(); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
public SessionCapacity(int maxCapacity) { | ||||||||||||||||||
this(0, maxCapacity); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
private void checkValidCapacity() { | ||||||||||||||||||
if (maxCapacity < MIN_CAPACITY) { | ||||||||||||||||||
throw new IllegalArgumentException(); | ||||||||||||||||||
} | ||||||||||||||||||
isValidCapacity(); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
public void increase() { | ||||||||||||||||||
capacity++; | ||||||||||||||||||
isValidCapacity(); | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+30
to
+33
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
ν΄λΉ μ½λλ₯Ό λ³΄κ³ μλ¬Έμ μ΄ λλκ² νκ°μ§ μλλ°μ, try {
SessionCapacity sessionCapacity = new SessionCapacity(10, 5);
sessionCapacity.increase();
} catch (CannotEnrollException e) {
System.out.println(e.getMessage());
}
// blabla μ ν
μ€νΈ μ½λλ κ·Έλ λ€λ©΄ 무μμ΄ λ¬Έμ μΌκΉμ? public void increase() {
isValidCapacity();
capacity++;
} μμΉλ₯Ό μ‘°μ ν΄λ³΄κ±°λ, |
||||||||||||||||||
|
||||||||||||||||||
@Override | ||||||||||||||||||
public int hashCode() { | ||||||||||||||||||
return Objects.hash(capacity, maxCapacity); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
@Override | ||||||||||||||||||
public boolean equals(Object object) { | ||||||||||||||||||
if (object == this) { | ||||||||||||||||||
return true; | ||||||||||||||||||
} | ||||||||||||||||||
if (object == null || getClass() != object.getClass()) { | ||||||||||||||||||
return false; | ||||||||||||||||||
} | ||||||||||||||||||
SessionCapacity sessionCapacity = (SessionCapacity) object; | ||||||||||||||||||
return sessionCapacity.capacity == this.capacity && sessionCapacity.maxCapacity == this.maxCapacity; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
private void isValidCapacity(){ | ||||||||||||||||||
if(this.capacity > this.maxCapacity) { | ||||||||||||||||||
throw new CannotEnrollException("μ΅λ μμ© μΈμμ νμ¬ μΈμμ΄ μ΄κ³Όν μ μλ€."); | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package nextstep.courses.domain.session; | ||
|
||
import java.time.LocalDate; | ||
|
||
public class SessionDate { | ||
private final LocalDate startDate; | ||
private final LocalDate endDate; | ||
|
||
public SessionDate(LocalDate startDate, LocalDate endDate) { | ||
this.startDate = startDate; | ||
this.endDate = endDate; | ||
Comment on lines
+10
to
+11
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. endDateκ° startDateλ³΄λ€ μ΄μ μ΄λ©΄ κ°μ²΄κ° μμ±μλκ² νλκ² λ νμ€νμ§ μμκΉμ? μλλ©΄, endDateκ° startDateλ³΄λ€ μ΄μ μ΄λΌλ μμ±λμ΄μΌνλ κ²½μ°κ° μλμ? |
||
} | ||
|
||
public boolean isBefore(LocalDate date) { | ||
return date.isBefore(startDate); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package nextstep.courses.domain.session; | ||
|
||
import nextstep.courses.InvalidImageException; | ||
|
||
import java.util.Objects; | ||
|
||
public class SessionImage { | ||
private static final int MAX_IMAGE_SIZE = 1000000; | ||
private static final int MIN_WIDTH = 300; | ||
private static final int MIN_HEIGHT = 200; | ||
private static final double WIDTH_PER_HEIGHT = 1.5; | ||
|
||
private final int width; | ||
private final int height; | ||
private final int size; | ||
private final SessionImageType imageType; | ||
|
||
public SessionImage(int width, int height, int size, String imageType) { | ||
this(width, height, size, SessionImageType.of(imageType)); | ||
} | ||
|
||
public SessionImage(int width, int height, int size, SessionImageType imageType) { | ||
this.width = width; | ||
this.height = height; | ||
this.size = size; | ||
this.imageType = imageType; | ||
checkValidSessionImage(); | ||
} | ||
|
||
private void checkValidSessionImage() { | ||
if (this.width < MIN_WIDTH || this.height < MIN_HEIGHT) { | ||
throw new InvalidImageException("μ΄λ―Έμ§μ widthλ 300ν½μ , heightλ 200ν½μ μ΄μμ΄μ΄μΌ νλ€."); | ||
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. μ‘°κ±΄μ΄ λ³κ²½λ λλ§λ€ μμΈ λ©μμ§κΉμ§ ν¨κ» λ³κ²½ν΄μΌνλκ²μ μ μ§λ³΄μμ 리μ€ν¬κ° μμ§ μμκΉμ? |
||
} | ||
if ((double) this.width / this.height != WIDTH_PER_HEIGHT) { | ||
throw new InvalidImageException("μ΄λ―Έμ§μ width, heightμ λΉμ¨μ 3:2μ¬μΌ νλ€."); | ||
} | ||
|
||
if (this.size > MAX_IMAGE_SIZE) { | ||
throw new InvalidImageException("μ΄λ―Έμ§μ ν¬κΈ°λ 1MB μ΄νμ¬μΌ νλ€."); | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(width, height, size, imageType); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (object == this) { | ||
return true; | ||
} | ||
if (object == null || getClass() != object.getClass()) { | ||
return false; | ||
} | ||
SessionImage image = (SessionImage) object; | ||
return Objects.equals(image.imageType, imageType) && image.width == width && image.height == height && image.size == size; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package nextstep.courses.domain.session; | ||
|
||
import nextstep.courses.InvalidImageException; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum SessionImageType { | ||
gif("gif"), jpg("jpg"), jpeg("jpeg"), png("png"), svg("svg"); | ||
|
||
private final String name; | ||
|
||
SessionImageType(String name) { | ||
this.name = name; | ||
} | ||
|
||
public static SessionImageType of(String name) { | ||
return Arrays.stream(values()) | ||
.filter(type -> type.name.equals(name)) | ||
.findFirst() | ||
.orElseThrow(InvalidImageException::new); | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package nextstep.courses.domain.session; | ||
|
||
public enum SessionState { | ||
PREPARING, | ||
RECRUITING, | ||
CLOSED; | ||
|
||
public boolean canRecruit(){ | ||
return this == RECRUITING; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package nextstep.courses.strategy; | ||
|
||
import nextstep.payments.domain.Payment; | ||
|
||
public class FreePaymentStrategy implements PaymentStrategy { | ||
@Override | ||
public boolean payable(Payment payment) { | ||
return true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,18 @@ | ||||||||||
package nextstep.courses.strategy; | ||||||||||
|
||||||||||
import nextstep.payments.domain.Payment; | ||||||||||
|
||||||||||
public class PaidPaymentStrategy implements PaymentStrategy { | ||||||||||
private final long price; | ||||||||||
|
||||||||||
public PaidPaymentStrategy(long price) { | ||||||||||
this.price = price; | ||||||||||
} | ||||||||||
|
||||||||||
@Override | ||||||||||
public boolean payable(Payment payment) { | ||||||||||
if (payment.isSameAmount(price)) | ||||||||||
return true; | ||||||||||
return false; | ||||||||||
Comment on lines
+14
to
+16
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
μ½κ² ννν μμλκ²μ μ½κ² ννν΄λ μ’μκ² κ°μμ~ |
||||||||||
} | ||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package nextstep.courses.strategy; | ||
|
||
import nextstep.payments.domain.Payment; | ||
|
||
public interface PaymentStrategy { | ||
boolean payable(Payment payment); | ||
} |
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.
ν΄λΉ μꡬμ¬νμ΄ κ΅¬νλμ§ μμμ΄μ κ° μμκΉμ?