-
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
๐ 2๋จ๊ณ - ์๊ฐ์ ์ฒญ(๋๋ฉ์ธ ๋ชจ๋ธ) ๋ฏธ์ ์๋ฃ #536
base: kbzz17
Are you sure you want to change the base?
Changes from all commits
7576ecd
90d9f98
9092248
803f52e
fb85cd9
1e8a01e
d34226c
9c2642f
500f8d6
373c0ce
4dd4621
80b91d5
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; | ||
|
||
public class CanNotApplyException extends Exception{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
public CanNotApplyException(String message) { | ||
super(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package nextstep.courses; | ||
|
||
public class ImageSizeRangeException extends Exception{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
public ImageSizeRangeException(String message) { | ||
super(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package nextstep.courses; | ||
|
||
public class ImageSizeRatioException extends Exception{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
public ImageSizeRatioException(String message) { | ||
super(message); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package nextstep.courses; | ||
|
||
public class NotAcceptedImageTypeException extends Exception{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
public NotAcceptedImageTypeException(String message) { | ||
super(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package nextstep.courses; | ||
|
||
public class OutOfImageCapacityException extends Exception{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
public OutOfImageCapacityException(String message) { | ||
super(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package nextstep.courses.domain; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import nextstep.courses.domain.session.Session; | ||
|
||
public class Course { | ||
private Long id; | ||
|
@@ -13,6 +15,8 @@ public class Course { | |
|
||
private LocalDateTime updatedAt; | ||
|
||
private List<Session> sessions; | ||
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. ์ธ์ ์ ์ถ๊ฐํ๋ addSession()๊ณผ ๊ฐ์ ๋ฉ์๋๋ ์์ด์ผ ํ์ง ์์๊น? |
||
|
||
public Course() { | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,13 @@ | ||||||
package nextstep.courses.domain.Image; | ||||||
|
||||||
public class Image { | ||||||
private final ImageCapacity capacity; | ||||||
private final ImageType type; | ||||||
private final ImageSize size; | ||||||
|
||||||
public Image(ImageCapacity capacity, ImageType type, ImageSize 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.
Suggested change
์์ ๊ฐ์ ์์ฑ์๋ ์ถ๊ฐ๋ก ์ง์ํ๋ ๊ฒ์ ์ด๋จ๊น? |
||||||
this.capacity = capacity; | ||||||
this.type = type; | ||||||
this.size = size; | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package nextstep.courses.domain.Image; | ||
|
||
import nextstep.courses.OutOfImageCapacityException; | ||
|
||
public class ImageCapacity { | ||
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 int LIMIT_CAPACITY = 1024; | ||
|
||
private final int capacity; | ||
|
||
/** | ||
* kilobyte ๊ธฐ์ค์ผ๋ก ์์ฑํ์์ต๋๋ค. | ||
* @param capacity | ||
*/ | ||
public ImageCapacity(int capacity) throws OutOfImageCapacityException { | ||
validCapacity(capacity); | ||
this.capacity = capacity; | ||
} | ||
|
||
private void validCapacity(int capacity) throws OutOfImageCapacityException { | ||
if (capacity > LIMIT_CAPACITY) { | ||
throw new OutOfImageCapacityException("์ด๋ฏธ์ง ์ฉ๋์ 1MB ์ดํ์ฌ์ผ ํฉ๋๋ค."); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package nextstep.courses.domain.Image; | ||
|
||
import nextstep.courses.ImageSizeRangeException; | ||
import nextstep.courses.ImageSizeRatioException; | ||
|
||
public class ImageSize { | ||
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 static int WIDTH_RATIO = 3; | ||
private static int HEIGHT_RATIO = 2; | ||
|
||
private final int width; | ||
private final int height; | ||
|
||
public ImageSize(int width, int height) throws Exception { | ||
validSizeRange(width, height); | ||
validSizeRatio(width, height); | ||
this.width = width; | ||
this.height = height; | ||
} | ||
|
||
private void validSizeRange(int width, int height) throws ImageSizeRangeException { | ||
if (width < 300 || height < 200) { | ||
throw new ImageSizeRangeException("๊ฐ๋ก 300 ์ด์ ์ธ๋ก 200 ์ด์์ด์ด์ผ ํฉ๋๋ค."); | ||
} | ||
} | ||
|
||
private void validSizeRatio(int width, int height) throws ImageSizeRatioException { | ||
if (width * HEIGHT_RATIO != height * WIDTH_RATIO) { | ||
throw new ImageSizeRatioException( | ||
"๊ฐ๋ก ์ธ๋ก ๋น์จ์ " + WIDTH_RATIO + " : " + HEIGHT_RATIO + "์ ๋๋ค"); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package nextstep.courses.domain.Image; | ||
|
||
import java.util.Arrays; | ||
import nextstep.courses.NotAcceptedImageTypeException; | ||
|
||
public enum ImageType { | ||
GIF, | ||
JPG, | ||
JPEG, | ||
PNG, | ||
SVG; | ||
|
||
public static ImageType of(String type) throws NotAcceptedImageTypeException { | ||
return Arrays.stream(ImageType.values()) | ||
.filter(value -> value.name().equals(type)) | ||
.findFirst() | ||
.orElseThrow(() -> new NotAcceptedImageTypeException("ํ์ฉ๋์ง ์๋ ์ด๋ฏธ์ง ํ์ ์ ๋๋ค.")); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,25 @@ | ||||||
package nextstep.courses.domain.session; | ||||||
|
||||||
import nextstep.courses.CanNotApplyException; | ||||||
import nextstep.courses.domain.Course; | ||||||
import nextstep.courses.domain.Image.Image; | ||||||
|
||||||
public class FreeSession extends Session{ | ||||||
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
|
||||||
private static final int FREE_COST = 0; | ||||||
|
||||||
public FreeSession(Image image, Period period, SessionStatus status, Course course) { | ||||||
super(image, period, status, course); | ||||||
} | ||||||
|
||||||
@Override | ||||||
public boolean isAppliable(int pay, int order) throws CanNotApplyException { | ||||||
validPay(pay); | ||||||
return true; | ||||||
} | ||||||
|
||||||
private static void validPay(int pay) throws CanNotApplyException { | ||||||
if(pay != FREE_COST){ | ||||||
throw new CanNotApplyException("๋ฌด๋ฃ ๊ฐ์์ ๋๋ค."); | ||||||
} | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package nextstep.courses.domain.session; | ||
|
||
import nextstep.courses.CanNotApplyException; | ||
import nextstep.courses.domain.Course; | ||
import nextstep.courses.domain.Image.Image; | ||
|
||
public class PaidSession extends Session { | ||
|
||
private final int fee; | ||
private final int limit; | ||
|
||
public PaidSession(Image image, Period period, SessionStatus status, Course course, int fee, | ||
int limit) { | ||
super(image, period, status, course); | ||
this.fee = fee; | ||
this.limit = limit; | ||
} | ||
|
||
@Override | ||
public boolean isAppliable(int pay, int order) throws CanNotApplyException { | ||
validPay(pay); | ||
validStudentsLimit(order); | ||
return fee == pay && order <= limit; | ||
} | ||
|
||
private void validStudentsLimit(int order) throws CanNotApplyException { | ||
if (order > limit) { | ||
throw new CanNotApplyException("์๊ฐ์์ด_๊ฝ_์ฐผ์ต๋๋ค"); | ||
} | ||
} | ||
|
||
private void validPay(int pay) throws CanNotApplyException { | ||
if (pay != fee) { | ||
throw new CanNotApplyException("์๊ฐ๋ฃ๋ฅผ ์ ๋ชป ๋ด์ จ์ต๋๋ค."); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package nextstep.courses.domain.session; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class Period { | ||
private final LocalDateTime startDate; | ||
private final LocalDateTime endDate; | ||
|
||
public Period(LocalDateTime startDate, LocalDateTime endDate) { | ||
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. ์์์ผ์ ์ข ๋ฃ์ผ๋ณด๋ค ์์์ผ ํ๋ค๋ ์ ํจ์ฑ ์ฒดํฌ๋ฅผ ์ถ๊ฐํด์ผ ํ์ง ์์๊น? |
||
this.startDate = startDate; | ||
this.endDate = endDate; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package nextstep.courses.domain.session; | ||
|
||
import nextstep.courses.CanNotApplyException; | ||
import nextstep.courses.domain.Course; | ||
import nextstep.courses.domain.Image.Image; | ||
import nextstep.courses.domain.user.NsUsers; | ||
import nextstep.payments.domain.Payment; | ||
import nextstep.payments.domain.Payments; | ||
import nextstep.users.domain.NsUser; | ||
|
||
public abstract class Session { | ||
|
||
private final long id; | ||
private final Image image; | ||
private final Period period; | ||
private final SessionStatus status; | ||
private final NsUsers users; | ||
private final Course course; | ||
private final Payments payments; | ||
|
||
public Session(Image image, Period period, SessionStatus status, Course course) { | ||
this.id = 0L; | ||
this.image = image; | ||
this.period = period; | ||
this.status = status; | ||
this.course = course; | ||
this.users = new NsUsers(); | ||
this.payments = new Payments(); | ||
} | ||
|
||
public NsUsers getUsers() { | ||
return users; | ||
} | ||
|
||
public abstract boolean isAppliable(int pay, int order) throws CanNotApplyException; | ||
|
||
public void apply(int pay, NsUser user) throws Exception { | ||
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. Session์ ์ธ์คํด์ค ๋ณ์๊ฐ ๋ง์์ง๊ณ ์๋ค. |
||
validSessionStatus(); | ||
isAppliable(pay, users.numberOfUsers() + 1); | ||
users.add(user); | ||
payments.add(toPayment(pay, user)); | ||
} | ||
|
||
public Payment toPayment(int pay, NsUser user) { | ||
return new Payment("0", id, user.getId(), (long) pay); | ||
} | ||
|
||
private void validSessionStatus() throws Exception { | ||
if (!status.equals(SessionStatus.RECRUIT)) { | ||
throw new CanNotApplyException("๋ชจ์ง ์ค์ธ ๊ฐ์๊ฐ ์๋๋๋ค."); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package nextstep.courses.domain.session; | ||
|
||
public enum SessionStatus { | ||
READY, | ||
RECRUIT, | ||
END | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package nextstep.courses.domain.user; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import nextstep.users.domain.NsUser; | ||
|
||
public class NsUsers { | ||
private final List<NsUser> users = new ArrayList<>(); | ||
|
||
public NsUsers() { | ||
} | ||
|
||
public int numberOfUsers(){ | ||
return users.size(); | ||
} | ||
|
||
public void add(NsUser user){ | ||
users.add(user); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package nextstep.payments.domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Payments { | ||
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. ๊ฒฐ์ ๊ฐ ์๋ฃ๋๋ค๊ณ ๊ฐ์ ํ๊ณ ๊ธฐ๋ฅ ๊ตฌํํ๊ณ ์๊ธฐ ๋๋ฌธ์ Payment ๊ด๋ จํด ํน๋ณํ ๋ง์ ์๊ฐ์ ํฌ์ํ์ง ์์๋ ๋๋ค. |
||
|
||
private final List<Payment> payments = new ArrayList<>(); | ||
|
||
public Payments() { | ||
} | ||
|
||
public void add(Payment payment){ | ||
payments.add(payment); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package nextstep.courses.domain.image; | ||
|
||
import nextstep.courses.OutOfImageCapacityException; | ||
import nextstep.courses.domain.Image.ImageCapacity; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ImageCapacityTest { | ||
|
||
@Test | ||
void ์ด๋ฏธ์ง_์ฉ๋์_1MB_์ดํ() { | ||
int capacity = 2_000; | ||
Assertions.assertThatThrownBy(() -> new ImageCapacity(capacity)) | ||
.isInstanceOf(OutOfImageCapacityException.class); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package nextstep.courses.domain.image; | ||
|
||
import nextstep.courses.ImageSizeRangeException; | ||
import nextstep.courses.ImageSizeRatioException; | ||
import nextstep.courses.domain.Image.ImageSize; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ImageSizeTest { | ||
|
||
@Test | ||
void ์ด๋ฏธ์ง_ํฌ๊ธฐ๋_๊ฐ๋ก_300_๋์ด_200_์ด์์ด์ด์ผ_ํฉ๋๋ค() { | ||
int width = 299; | ||
int height = 200; | ||
|
||
Assertions.assertThatThrownBy(() -> new ImageSize(width, height)) | ||
.isInstanceOf(ImageSizeRangeException.class); | ||
} | ||
|
||
@Test | ||
void ์ด๋ฏธ์ง_๋น์จ์_๊ฐ๋ก_3_์ธ๋ก_2_์ด์ผ_ํฉ๋๋ค() { | ||
int width = 400; | ||
int height = 200; | ||
|
||
Assertions.assertThatThrownBy(() -> new ImageSize(width, height)) | ||
.isInstanceOf(ImageSizeRatioException.class); | ||
} | ||
|
||
} |
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.