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

๐Ÿš€ 2๋‹จ๊ณ„ - ์ˆ˜๊ฐ•์‹ ์ฒญ(๋„๋ฉ”์ธ ๋ชจ๋ธ) ๋ฏธ์…˜์™„๋ฃŒ #536

Open
wants to merge 12 commits into
base: kbzz17
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
12 commits
Select commit Hold shift + click to select a range
7576ecd
[feat] ์ด๋ฏธ์ง€ ์šฉ๋Ÿ‰์€ 1MB ์ดํ•˜์—ฌ์•ผ ํ•œ๋‹ค.
kbzz17 May 12, 2024
90d9f98
[feat] ํ—ˆ์šฉ๋˜๋Š” ์ด๋ฏธ์ง€ ํƒ€์ž…์€ ์ œํ•œ๋˜์–ด ์žˆ๋‹ค.
kbzz17 May 12, 2024
9092248
[feat] ์ด๋ฏธ์ง€ ํฌ๊ธฐ์™€ ๋น„์œจ์ด ๋งž์ง€ ์•Š์œผ๋ฉด ์—๋Ÿฌ ๋ฐœ์ƒ
kbzz17 May 12, 2024
803f52e
[feat] ์ด๋ฏธ์ง€ ํด๋ž˜์Šค ์ƒ์„ฑ
kbzz17 May 13, 2024
fb85cd9
[feat] ๊ฐ•์˜๋Š” ์‹œ์ž‘์ผ๊ณผ ์ข…๋ฃŒ์ผ์„ ๊ฐ€์ง„๋‹ค.
kbzz17 May 13, 2024
1e8a01e
[feat] ์œ ๋ฃŒ ๊ฐ•์˜๋Š” ๊ฐ•์˜๋ฃŒ๋ฅผ ์ง€๋ถˆํ•ด์•ผ ํ•˜๊ณ  ์ˆ˜๊ฐ•์ธ์› ์ œํ•œ์ด ์žˆ๋‹ค.
kbzz17 May 13, 2024
d34226c
[feat] ๋ฌด๋ฃŒ ๊ฐ•์˜๋Š” ๋ˆ๊ณผ ์ˆ˜๊ฐ•์ƒ ์ œํ•œ์ด ์—†๋‹ค.
kbzz17 May 13, 2024
9c2642f
[feat] ๊ฐ•์˜ ์ƒํƒœ๋Š” ์ค€๋น„, ๋ชจ์ง‘, ๋งˆ๊ฐ์œผ๋กœ ์ด๋ฃจ์–ด์ง„๋‹ค.
kbzz17 May 13, 2024
500f8d6
[feat] ์ˆ˜๊ฐ•์‹ ์ฒญํ•œ ์œ ์ €๋“ค์„ ๋‹ด๋Š” Users ํด๋ž˜์Šค ๊ฐœ๋ฐœ
kbzz17 May 13, 2024
373c0ce
[feat] ๊ฐ•์˜ ์ˆ˜๊ฐ•์‹ ์ฒญ ๊ธฐ๋Šฅ ๊ฐœ๋ฐœ
kbzz17 May 13, 2024
4dd4621
[feat] Course, Session ๋งตํ•‘
kbzz17 May 13, 2024
80b91d5
[feat] payment ๊ตฌํ˜„
kbzz17 May 13, 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
9 changes: 9 additions & 0 deletions src/main/java/nextstep/courses/CanNotApplyException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package nextstep.courses;

public class CanNotApplyException extends Exception{
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public class CanNotApplyException extends Exception{
public class CanNotApplyException extends Exception {

private static final long serialVersionUID = 1L;

public CanNotApplyException(String message) {
super(message);
}
}
9 changes: 9 additions & 0 deletions src/main/java/nextstep/courses/ImageSizeRangeException.java
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);
}
}
10 changes: 10 additions & 0 deletions src/main/java/nextstep/courses/ImageSizeRatioException.java
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);
}
}
4 changes: 4 additions & 0 deletions src/main/java/nextstep/courses/domain/Course.java
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;
Expand All @@ -13,6 +15,8 @@ public class Course {

private LocalDateTime updatedAt;

private List<Session> sessions;
Copy link
Contributor

Choose a reason for hiding this comment

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

์„ธ์…˜์„ ์ถ”๊ฐ€ํ•˜๋Š” addSession()๊ณผ ๊ฐ™์€ ๋ฉ”์„œ๋“œ๋„ ์žˆ์–ด์•ผ ํ•˜์ง€ ์•Š์„๊นŒ?


public Course() {
}

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/nextstep/courses/domain/Image/Image.java
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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public Image(ImageCapacity capacity, ImageType type, ImageSize size) {
public Image(int capacity, ImageType type, int width, int height ) {

์œ„์•„ ๊ฐ™์€ ์ƒ์„ฑ์ž๋„ ์ถ”๊ฐ€๋กœ ์ง€์›ํ•˜๋Š” ๊ฒƒ์€ ์–ด๋–จ๊นŒ?

this.capacity = capacity;
this.type = type;
this.size = size;
}
}
24 changes: 24 additions & 0 deletions src/main/java/nextstep/courses/domain/Image/ImageCapacity.java
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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 ์ดํ•˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.");
}
}
}
33 changes: 33 additions & 0 deletions src/main/java/nextstep/courses/domain/Image/ImageSize.java
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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 + "์ž…๋‹ˆ๋‹ค");
}
}
}
19 changes: 19 additions & 0 deletions src/main/java/nextstep/courses/domain/Image/ImageType.java
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("ํ—ˆ์šฉ๋˜์ง€ ์•Š๋Š” ์ด๋ฏธ์ง€ ํƒ€์ž…์ž…๋‹ˆ๋‹ค."));
}
}
25 changes: 25 additions & 0 deletions src/main/java/nextstep/courses/domain/session/FreeSession.java
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{
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public class FreeSession extends Session{
public class FreeSession extends Session {

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("๋ฌด๋ฃŒ ๊ฐ•์˜์ž…๋‹ˆ๋‹ค.");
}
}
}
37 changes: 37 additions & 0 deletions src/main/java/nextstep/courses/domain/session/PaidSession.java
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("์ˆ˜๊ฐ•๋ฃŒ๋ฅผ ์ž˜ ๋ชป ๋‚ด์…จ์Šต๋‹ˆ๋‹ค.");
}
}
}
13 changes: 13 additions & 0 deletions src/main/java/nextstep/courses/domain/session/Period.java
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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

์‹œ์ž‘์ผ์€ ์ข…๋ฃŒ์ผ๋ณด๋‹ค ์•ž์„œ์•ผ ํ•œ๋‹ค๋Š” ์œ ํšจ์„ฑ ์ฒดํฌ๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผ ํ•˜์ง€ ์•Š์„๊นŒ?

this.startDate = startDate;
this.endDate = endDate;
}
}
54 changes: 54 additions & 0 deletions src/main/java/nextstep/courses/domain/session/Session.java
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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Session์˜ ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜๊ฐ€ ๋งŽ์•„์ง€๊ณ  ์žˆ๋‹ค.
Session์ด ๊ฐ€์ง€๋Š” ๊ฐ’ ์ค‘ ์ˆ˜๊ฐ•์‹ ์ฒญ๊ณผ ๊ด€๋ จ์žˆ๋Š” ๊ฐ’์„ ๊ฐ€์ง€๋Š” Enrollment์™€ ๊ฐ™์€ ๊ฐ์ฒด๋ฅผ ๋ถ„๋ฆฌํ•˜๊ณ  ์ˆ˜๊ฐ• ์‹ ์ฒญ ๋กœ์ง์„ ์ด ๊ฐ์ฒด๋กœ ๋ถ„๋ฆฌํ•˜๋ฉด ์–ด๋–จ๊นŒ?
๋ถ„๋ฆฌํ–ˆ์„ ๋•Œ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ๋ฐ ํ…Œ์ŠคํŠธ ๊ด€์ ์—์„œ ์–ป๋Š” ์ด์ ์ด ์žˆ์„๊นŒ?

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
}
20 changes: 20 additions & 0 deletions src/main/java/nextstep/courses/domain/user/NsUsers.java
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);
}
}
16 changes: 16 additions & 0 deletions src/main/java/nextstep/payments/domain/Payments.java
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
}
}
17 changes: 17 additions & 0 deletions src/test/java/nextstep/courses/domain/image/ImageCapacityTest.java
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);
}

}
29 changes: 29 additions & 0 deletions src/test/java/nextstep/courses/domain/image/ImageSizeTest.java
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);
}

}
Loading