-
Notifications
You must be signed in to change notification settings - Fork 248
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๋จ๊ณ - ์๊ฐ์ ์ฒญ(๋๋ฉ์ธ ๋ชจ๋ธ) #627
base: mingulee-devel
Are you sure you want to change the base?
Changes from 22 commits
f89ccf9
372331e
8928f60
d965af3
a22f18e
e9340bd
1ec08ae
f320b7b
e379e60
8311e79
c3837de
6a0964e
bcae477
dcea385
3423226
2a43351
82675be
f787e17
26e958f
cf83180
6355517
786f774
950b4a8
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,10 @@ | ||
package nextstep.courses.domain.session; | ||
|
||
import nextstep.payments.domain.Payment; | ||
|
||
public class FreeSession implements SessionStrategy { | ||
@Override | ||
public boolean canEnroll(Payment payment) { | ||
return true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package nextstep.courses.domain.session; | ||
|
||
import nextstep.payments.domain.Payments; | ||
import nextstep.payments.domain.Payment; | ||
|
||
public class PaidSession implements SessionStrategy { | ||
|
||
private int maxEnrollmentCount; | ||
private int currentEnrollmentCount; | ||
private int tuitionFee; | ||
|
||
private Payments payments; | ||
|
||
public PaidSession(int maxEnrollmentCount, int currentEnrollmentCount, int tuitionFee){ | ||
this.maxEnrollmentCount = maxEnrollmentCount; | ||
this.currentEnrollmentCount = currentEnrollmentCount; | ||
this.tuitionFee = tuitionFee; | ||
this.payments = new Payments(); | ||
} | ||
|
||
private boolean isFull() { | ||
return maxEnrollmentCount <= currentEnrollmentCount; | ||
} | ||
|
||
public void enroll(Payment payment){ //todo | ||
if(canEnroll(payment)){ | ||
payments.add(payment); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean canEnroll(Payment payment) { | ||
return !isFull() && payment.isTuitionPaid(tuitionFee); | ||
} | ||
Comment on lines
+25
to
+34
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 interface SessionEnrollStrategy {
void enroll(Payment payment);
} ๊ฐ ๋์ด์ผํ๊ณ , public class PaidSessionEnrollStrategy {
// ..
public void enroll(Payment payment) {
// canEnroll์ด ์๋ ๊ฒฝ์ฐ ์์ธ
// count๋ฅผ ์ฌ๋ฆฌ๊ณ ๊ฒฐ์ ์ ๋ณด ์ ์ฅ ์ด ๋ ์ ์๊ฒ ์ฃ . ๋ค๋ง ํด๋น ํด๋์ค๋ ์ ๋ต์ผ๋ก ๋ถ๋ฆฌ๊ณ ์๊ธฐ ๋๋ฌธ์ ํผ๋์ ์ค ์ ์๋๋ฐ์. "์ ๋ต"์ด๋ผ๋ ๊ฒ์ ์ด๋ค ํ์๋ฅผ ์ด๋ป๊ฒ ์คํํ๋๋๊ฐ ์ฃผ์ ๊ด์ฌ์ฌ์ด์ง ์ํ๋ฅผ ๋ค๊ณ ๊ด๋ฆฌํ๋ฉด์ ์ ๋ต์ ์ถ๊ตฌํ๋๊ฑด ์ ๋ต์์ฒด์ ์ฑ ์์ ํ์ฅ์์ผ๋ฒ๋ฆด ์ ์์ด์. ์ถ์ํ๋ฅผ ํตํ ์ ๊ทผ์ ๋ง์ง๋ง ์ ๋ต์ด๋๋ ๊ณ ๋ฏผํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ๋ค์ :) |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package nextstep.courses.domain.session; | ||
|
||
import nextstep.courses.domain.session.coverImage.SessionCoverImage; | ||
import nextstep.payments.domain.Payment; | ||
|
||
import java.time.LocalDate; | ||
|
||
public class 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.
|
||
|
||
private SessionDate sessionDate; | ||
private SessionCoverImage sessionCoverImage; | ||
private SessionStatus sessionStatus; | ||
private SessionStrategy sessionStrategy; | ||
|
||
public Session(SessionCoverImage sessionCoverImage, SessionStatus sessionStatus, SessionStrategy sessionStrategy) { | ||
this(null, null, sessionCoverImage, sessionStatus, sessionStrategy); | ||
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. ๋๋ค null์ธ ์ผ์ด์ค๋ฅผ ์์ฑ์์์ ์ง์ํ๋ ์ด์ ๊ฐ ์์๊น์? |
||
} | ||
|
||
public Session(LocalDate startDate, LocalDate endDate, SessionCoverImage sessionCoverImage, SessionStatus sessionStatus, SessionStrategy sessionStrategy) { | ||
this.sessionDate = new SessionDate(startDate, endDate); | ||
this.sessionCoverImage = sessionCoverImage; | ||
this.sessionStatus = sessionStatus; | ||
this.sessionStrategy = sessionStrategy; | ||
} | ||
|
||
public boolean isValidCoverImage() { | ||
return sessionCoverImage.isValidCoverImage(); | ||
} | ||
|
||
public boolean canEnroll(Payment payment) { | ||
return sessionStrategy.canEnroll(payment) && isRecruiting(); | ||
} | ||
|
||
private boolean isRecruiting() { | ||
return sessionStatus.isRecruiting(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package nextstep.courses.domain.session; | ||
|
||
import java.time.LocalDate; | ||
|
||
public class SessionDate { | ||
private LocalDate startDate; | ||
private LocalDate endDate; | ||
|
||
public SessionDate(LocalDate startDate, LocalDate endDate){ | ||
this.startDate = startDate; | ||
this.endDate = endDate; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package nextstep.courses.domain.session; | ||
|
||
public enum SessionStatus { | ||
|
||
PREPARING, | ||
RECRUITING, | ||
CLOSED; | ||
|
||
public boolean isRecruiting(){ | ||
return this == RECRUITING; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package nextstep.courses.domain.session; | ||
|
||
import nextstep.payments.domain.Payment; | ||
|
||
@FunctionalInterface | ||
public interface SessionStrategy { | ||
boolean canEnroll(Payment payment); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package nextstep.courses.domain.session; | ||
|
||
import java.util.List; | ||
|
||
public class Sessions { | ||
private List<Session> values; | ||
} | ||
Comment on lines
+5
to
+7
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,26 @@ | ||
package nextstep.courses.domain.session.coverImage; | ||
|
||
public class ImageDimensions { | ||
private int width; | ||
private int height; | ||
|
||
private static final int MIN_WIDTH = 300; | ||
private static final int MIN_HEIGHT = 200; | ||
private static final int WIDTH_RATIO = 3; | ||
private static final int HEIGHT_RATIO = 2; | ||
|
||
public ImageDimensions(int width, int height) { | ||
this.width = width; | ||
this.height = height; | ||
} | ||
|
||
public boolean validDimensions() { | ||
Comment on lines
+12
to
+17
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. ์์ฑ์์์ validation์ ํ์ง ์์ผ์๋ ์ด์ ๊ฐ ์์๊น์? ๊ฐ์ฒด์ ์์ฑ์ ๊ฐ์ฒด๊ฐ ๋ด๋นํ๋ ๊ฒ์ด ๊ฐ์ฒด ์์ฑ์ ์์ ์ฑ์ ๋ณด์ฅํด์ :) |
||
if (width < MIN_WIDTH || height < MIN_HEIGHT) { | ||
throw new IllegalArgumentException("์ด๋ฏธ์ง์ ๋๋น๋ 300ํฝ์ , ๋์ด๋ 200ํฝ์ ์ด์์ด์ด์ผ ํฉ๋๋ค."); | ||
} | ||
if (width * HEIGHT_RATIO != height * WIDTH_RATIO) { | ||
throw new IllegalArgumentException("๋๋น์ ๋์ด์ ๋น์จ์ 3:2์ฌ์ผ ํฉ๋๋ค."); | ||
} | ||
return true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package nextstep.courses.domain.session.coverImage; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum ImageExtension { | ||
GIF, | ||
JPG, | ||
JPEG, | ||
PNG, | ||
SVG, | ||
BMP; | ||
|
||
public static boolean validExtension(ImageExtension extension) { | ||
if (!Arrays.asList(GIF, JPG, JPEG, PNG, SVG).contains(extension)) { | ||
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 IllegalArgumentException("ํ์ฉ๋์ง ์์ ํ์ฅ์ ์ ๋๋ค."); | ||
} | ||
return true; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package nextstep.courses.domain.session.coverImage; | ||
|
||
public class ImageSize { | ||
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. ๋ถ๋ณ์ผ ์ ์๋ ํ๋๋ค์ ๋ชจ๋ ๋ถ๋ณ์ผ๋ก ์์ ํด์ฃผ์๋ฉด ์ข์ ๊ฒ ๊ฐ์์ :) |
||
|
||
private static final int MAX_SIZE = 1; | ||
|
||
public ImageSize(int size) { | ||
this.size = size; | ||
} | ||
|
||
public boolean validSize() { | ||
if (size > MAX_SIZE) { | ||
throw new IllegalArgumentException("์ด๋ฏธ์ง๋ 1MB ์ดํ์ฌ์ผ ํฉ๋๋ค."); | ||
} | ||
return true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package nextstep.courses.domain.session.coverImage; | ||
|
||
public class SessionCoverImage { | ||
private ImageSize imageSize; | ||
private ImageExtension imageExtension; | ||
private ImageDimensions imageDimensions; | ||
|
||
public SessionCoverImage(int size, ImageExtension imageExtension, int width, int height) { | ||
this(new ImageSize(size), imageExtension, new ImageDimensions(width, height)); | ||
} | ||
|
||
public SessionCoverImage(ImageSize imageSize, ImageExtension imageExtension, ImageDimensions imageDimensions) { | ||
this.imageSize = imageSize; | ||
this.imageExtension = imageExtension; | ||
this.imageDimensions = imageDimensions; | ||
} | ||
|
||
public boolean isValidCoverImage() { | ||
return imageSize.validSize() | ||
&& ImageExtension.validExtension(imageExtension) | ||
&& imageDimensions.validDimensions(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package nextstep.payments.domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Payments { | ||
private List<Payment> values = new ArrayList<>(); | ||
|
||
public void add(Payment payment){ | ||
values.add(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.
Session
์ด๋ผ๋ ๋๋ฉ์ธ์ด ์ด๋ฏธ ์๊ณ ํ์ฌ ๊ตฌํ์ฒด๋ Session์ ๋ฐ๋ฅธ ๊ฒฐ์ ์ ๋ต์ด๊ธฐ ๋๋ฌธ์ ๋ค์ด๋ฐ์ดFreeSessionEnrollStrategy
์ ๊ฐ์ด ์กฐ๊ธ ๋ ๋ช ํํ๋ฉด ์ข์ ๊ฒ ๊ฐ์์ :)