Skip to content

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

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

Open
wants to merge 12 commits into
base: nno0obb
Choose a base branch
from
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.gradle.jvmargs=-Dfile.encoding=UTF-8
org.gradle.console=plain
org.gradle.java.home=/opt/homebrew/Cellar/openjdk@11/11.0.26/libexec/openjdk.jdk/Contents/Home
org.gradle.java.home=/opt/homebrew/Cellar/openjdk@11/11.0.26/libexec/openjdk.jdk/Contents/Home
# ๋„ต, ์œ„ ์„ค์ •์€ IDE ์—์„œ Java ์‹คํ–‰ ํ™˜๊ฒฝ์„ ์œ„ํ•ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

Choose a reason for hiding this comment

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

์ด๊ฑธ ์„ค์ •ํ•˜๊ฒŒ๋˜๋ฉด gradle์„ ์‹คํ–‰ํ•˜๋Š” ๊ณผ์ •์—์„œ ํ•ด๋‹น path๊ฐ€ ๋น„์–ด์žˆ๋Š” ๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ๊ฒฝ์šฐ์—๋Š” ์‹คํ–‰์ด ๋ถˆ๊ฐ€๋Šฅํ•  ๊ฒƒ ๊ฐ™์•„์š”. ์‹ค์ œ ์„œ๋ฒ„์—์„œ๋„ ๋ˆ„๋ฝ๋˜๋ฉด ์‹คํ–‰์ด ๋˜์ง€ ์•Š์„ ๊ฒƒ์ด๊ตฌ์š”.

์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰๊ณผ ๊ด€๋ จ๋œ gradle์„ ์„ค์ •ํ• ๋•Œ๋Š” ๊ฐ€๋Šฅํ•˜๋ฉด ํŠน์ • path์— ์˜์กดํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค :)

24 changes: 24 additions & 0 deletions src/main/java/nextstep/README.md

Choose a reason for hiding this comment

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

ํ…Œ์ŠคํŠธ ์ถ”๊ฐ€๋‚˜ ์ˆ˜์ •์€ ์ž์œ ๋กญ๊ฒŒ ์ง„ํ–‰ํ•ด์ฃผ์…”๋„ ๋ฉ๋‹ˆ๋‹ค ๐Ÿ˜„

Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,27 @@
- [x] QnaService์˜ ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง์„ ๋„๋ฉ”์ธ ๋ชจ๋ธ๋กœ ์ด๋™ํ•˜๋Š” ๋ฆฌํŒฉํ„ฐ๋ง์„ ์ง„ํ–‰ํ•  ๋•Œ TDD๋กœ ๊ตฌํ˜„ํ•œ๋‹ค.
- [x] QnaService์˜ deleteQuestion() ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•œ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋Š” src/test/java ํด๋” nextstep.qna.service.QnaServiceTest์ด๋‹ค.
- [x]๋„๋ฉ”์ธ ๋ชจ๋ธ๋กœ ๋กœ์ง์„ ์ด๋™ํ•œ ํ›„์—๋„ QnaServiceTest์˜ ๋ชจ๋“  ํ…Œ์ŠคํŠธ๋Š” ํ†ต๊ณผํ•ด์•ผ ํ•œ๋‹ค.

## # Step1 ํ”ผ๋“œ๋ฐฑ

- [x] `gradle.properties` ์˜ "org.gradle.java.home" ๋ฌธ์˜
- [x] "answers" ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ์ผ๊ธ‰์ปฌ๋ ‰์…˜ ์ถ”๊ฐ€
- [x] ํ…Œ์ŠคํŠธ ์ด๋ฆ„ ๊ตฌ์ฒด์ ์œผ๋กœ ๋ช…์‹œ

## # Step2 ์š”๊ตฌ์‚ฌํ•ญ

- [x] ๊ณผ์ •(Course)์€ ๊ธฐ์ˆ˜ ๋‹จ์œ„๋กœ ์šด์˜ํ•˜๋ฉฐ, ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๊ฐ•์˜(Session)๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋‹ค.
- [x] ๊ฐ•์˜๋Š” ์‹œ์ž‘์ผ๊ณผ ์ข…๋ฃŒ์ผ์„ ๊ฐ€์ง„๋‹ค.
- [x] ๊ฐ•์˜๋Š” ๊ฐ•์˜ ์ปค๋ฒ„ ์ด๋ฏธ์ง€ ์ •๋ณด๋ฅผ ๊ฐ€์ง„๋‹ค.
- [x] ์ด๋ฏธ์ง€ ํฌ๊ธฐ๋Š” 1MB ์ดํ•˜์—ฌ์•ผ ํ•œ๋‹ค.
- [x] ์ด๋ฏธ์ง€ ํƒ€์ž…์€ gif, jpg(jpeg ํฌํ•จ), png, svg ๋งŒ ํ—ˆ์šฉํ•œ๋‹ค.
- [x] ์ด๋ฏธ์ง€์˜ width๋Š” 300ํ”ฝ์…€, height๋Š” 200ํ”ฝ์…€ ์ด์ƒ์ด์–ด์•ผ ํ•˜๋ฉฐ, width์™€ height์˜ ๋น„์œจ์€ 3:2์—ฌ์•ผ ํ•œ๋‹ค.
- [x] ๊ฐ•์˜๋Š” ๋ฌด๋ฃŒ ๊ฐ•์˜์™€ ์œ ๋ฃŒ ๊ฐ•์œผ๋กœ ๋‚˜๋‰œ๋‹ค.
- [x] ๋ฌด๋ฃŒ ๊ฐ•์˜๋Š” ์ตœ๋Œ€ ์ˆ˜๊ฐ• ์ธ์› ์ œํ•œ์ด ์—†๋‹ค.
- [x] ์œ ๋ฃŒ ๊ฐ•์˜๋Š” ๊ฐ•์˜ ์ตœ๋Œ€ ์ˆ˜๊ฐ• ์ธ์›์„ ์ดˆ๊ณผํ•  ์ˆ˜ ์—†๋‹ค.
* ์œ ๋ฃŒ ๊ฐ•์˜๋Š” ์ˆ˜๊ฐ•์ƒ์ด ๊ฒฐ์ œํ•œ ๊ธˆ์•ก๊ณผ ์ˆ˜๊ฐ•๋ฃŒ๊ฐ€ ์ผ์น˜ํ•  ๋•Œ ์ˆ˜๊ฐ• ์‹ ์ฒญ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
- [x] ๊ฐ•์˜ ์ƒํƒœ๋Š” ์ค€๋น„์ค‘, ๋ชจ์ง‘์ค‘, ์ข…๋ฃŒ 3๊ฐ€์ง€ ์ƒํƒœ๋ฅผ ๊ฐ€์ง„๋‹ค.
- [x] ๊ฐ•์˜ ์ˆ˜๊ฐ•์‹ ์ฒญ์€ ๊ฐ•์˜ ์ƒํƒœ๊ฐ€ ๋ชจ์ง‘์ค‘์ผ ๋•Œ๋งŒ ๊ฐ€๋Šฅํ•˜๋‹ค.

* ์œ ๋ฃŒ ๊ฐ•์˜์˜ ๊ฒฝ์šฐ ๊ฒฐ์ œ๋Š” ์ด๋ฏธ ์™„๋ฃŒํ•œ ๊ฒƒ์œผ๋กœ ๊ฐ€์ •ํ•˜๊ณ  ์ดํ›„ ๊ณผ์ •์„ ๊ตฌํ˜„ํ•œ๋‹ค.
* ๊ฒฐ์ œ๋ฅผ ์™„๋ฃŒํ•œ ๊ฒฐ์ œ ์ •๋ณด๋Š” payments ๋ชจ๋“ˆ์„ ํ†ตํ•ด ๊ด€๋ฆฌ๋˜๋ฉฐ, ๊ฒฐ์ œ ์ •๋ณด๋Š” Payment ๊ฐ์ฒด์— ๋‹ด๊ฒจ ๋ฐ˜ํ™˜๋œ๋‹ค.
22 changes: 22 additions & 0 deletions src/main/java/nextstep/courses/domain/AttendeeList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package nextstep.courses.domain;

import java.util.ArrayList;
import java.util.List;

import nextstep.users.domain.NsUser;

public class AttendeeList {

Choose a reason for hiding this comment

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

์ด๋ฅผ ์œ„ํ•ด AttendeeList ๊ฐ€ ๊ผญ ํ•„์š”ํ•ด์ง„๊ฒƒ ๊ฐ™์€๋ฐ ์š”๊ตฌ์‚ฌํ•ญ์—๋Š” ๋ช…์‹œ๋˜์–ด ์žˆ์ง€ ์•Š์ง€๋งŒ ๋‚˜๋ฆ„๋Œ€๋กœ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ๊นŒ์ง€๊ฐ€ ์ด๋ฒˆ ์Šคํ…์˜ ์˜๋„์ผ๊นŒ์š”?

์š”๊ตฌ์‚ฌํ•ญ์—๋Š” ์–ด๋–ค ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค์–ด๋ผ๋ผ๋Š” ๊ตฌํ˜„๋‚ด์šฉ์€ ๋ช…์‹œํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ํ™๊ท ๋‹˜์ด ์ƒ๊ฐํ•ด์ฃผ์‹œ๋Š” ๋ฐฉํ–ฅ๋Œ€๋กœ ๊ตฌํ˜„์„ ํ•ด์ฃผ์‹œ๋ฉด ๋˜์–ด์š” :)

private final List<NsUser> attendees;

public AttendeeList() {
this.attendees = new ArrayList<>();
}

public void add(NsUser attendee) {
attendees.add(attendee);
}

public Long size() {
return (long) attendees.size();
}
}
39 changes: 36 additions & 3 deletions src/main/java/nextstep/courses/domain/Course.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package nextstep.courses.domain;

import java.awt.image.BufferedImage;
import java.time.LocalDateTime;

public class Course {
Expand All @@ -13,19 +14,43 @@ public class Course {

private LocalDateTime updatedAt;

private SessionList sessions;

private String courseCoverImageFilePath;

private CourseCoverImage courseCoverImage;

private Long maxAttendees;

private CourseStatus courseStatus;

private AttendeeList attendees = new AttendeeList();

public Course() {
}

public Course(String title, Long creatorId) {
this(0L, title, creatorId, LocalDateTime.now(), null);
public Course(String title, Long creatorId, String courseCoverImageFilePath, Long maxAttendees) {
this(0L, title, creatorId, LocalDateTime.now(), null, courseCoverImageFilePath, maxAttendees, CourseStatus.PREPARING);
}

public Course(String title, Long creatorId, String courseCoverImageFilePath, Long maxAttendees, CourseStatus courseStatus) {
this(0L, title, creatorId, LocalDateTime.now(), null, courseCoverImageFilePath, maxAttendees, courseStatus);
}

public Course(Long id, String title, Long creatorId, LocalDateTime createdAt, LocalDateTime updatedAt) {
public Course(Long id, String title, Long creatorId, LocalDateTime createdAt, LocalDateTime updatedAt, String courseCoverImageFilePath, Long maxAttendees, CourseStatus courseStatus) {
this.id = id;
this.title = title;
this.creatorId = creatorId;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
this.courseCoverImageFilePath = courseCoverImageFilePath;
this.courseCoverImage = new CourseCoverImage(courseCoverImageFilePath);
this.maxAttendees = maxAttendees;
this.courseStatus = courseStatus;
}

public AttendeeList getAttendees() {
return attendees;
}

public String getTitle() {
Expand All @@ -40,6 +65,14 @@ public LocalDateTime getCreatedAt() {
return createdAt;
}

public Long getMaxAttendees() {
return maxAttendees;
}

public CourseStatus getCourseStatus() {
return courseStatus;
}

@Override
public String toString() {
return "Course{" +
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/nextstep/courses/domain/CourseCoverImage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package nextstep.courses.domain;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.Arrays;

import javax.imageio.ImageIO;

public class CourseCoverImage {

Choose a reason for hiding this comment

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

CourseCoverImage ๋Š” ์ž์ฒด์ ์œผ๋กœ ์ด๋ฏธ์ง€๋ฅผ ๋„ฃ์–ด์„œ ํ…Œ์ŠคํŠธ ํ•˜๋Š” ๊ฒƒ์ด ๋งž์„๊นŒ์š”?
"Image" ๊ด€๋ จ ์ž๋ฐ” ํด๋ž˜์Šค๊นŒ์ง€ ๊ณต๋ถ€ํ•˜๋Š” ๊ฒƒ์„ ์˜๋„ํ•˜์‹  ๊ฒƒ์ธ์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.

์ž๋ฐ”ํด๋ž˜์Šค๋ฅผ ํ•™์Šตํ•  ์ •๋„๊นŒ์ง€๋Š” ํ•„์š”์—†๊ณ , ์š”๊ตฌ๋œ ๋‚ด์šฉ์˜ ์ด๋ฏธ์ง€ ๊ด€๋ จ๋œ ๋„๋ฉ”์ธ๋กœ์ง์„ ์ฒ˜๋ฆฌํ•˜๋Š” ์ •๋„๋ฉด ์ถฉ๋ถ„ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๐Ÿ˜„


private static final String[] SUPPORTED_IMAGE_EXTENSIONS = {".gif", ".jpg", ".jpeg", ".png", ".svg"};
private static final int MIN_WIDTH = 300;
private static final int MIN_HEIGHT = 200;
private static final String DEFAULT_IMAGE_FILE_PATH = "src/test/resources/images/default.jpg";

private String imageFilePath;
private File imageFile;

private BufferedImage courseCoverImageData;
Comment on lines +18 to +21

Choose a reason for hiding this comment

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

Suggested change
private String imageFilePath;
private File imageFile;
private BufferedImage courseCoverImageData;
private final String imageFilePath;
private final File imageFile;
private final BufferedImage courseCoverImageData;

๋ถˆ๋ณ€ํ•  ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”!


public CourseCoverImage(String imageFilePath) {
validateImage(imageFilePath);
this.imageFilePath = imageFilePath;
}

private void validateImage(String imageFilePath) {
if (imageFilePath == null) {
imageFilePath = DEFAULT_IMAGE_FILE_PATH;
}

if (Arrays.stream(SUPPORTED_IMAGE_EXTENSIONS).noneMatch(imageFilePath::endsWith)) {

Choose a reason for hiding this comment

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

๐Ÿ‘

throw new IllegalArgumentException("์ง€์›ํ•˜์ง€ ์•Š๋Š” ์ด๋ฏธ์ง€ ํ˜•์‹์ž…๋‹ˆ๋‹ค. (์ง€์› ํ˜•์‹: gif, jpg, jpeg, png, svg)");
}

try {
imageFile = new File(imageFilePath);
if (!imageFile.exists()) {
throw new IllegalArgumentException("๊ฐ•์˜ ์ปค๋ฒ„ ์ด๋ฏธ์ง€๋ฅผ ์ฝ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}
} catch (Exception e) {
throw new IllegalArgumentException("๊ฐ•์˜ ์ปค๋ฒ„ ์ด๋ฏธ์ง€๋ฅผ ์ฝ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}

try {
courseCoverImageData = ImageIO.read(imageFile);
if (courseCoverImageData == null) {
throw new IllegalArgumentException("๊ฐ•์˜ ์ปค๋ฒ„ ์ด๋ฏธ์ง€๋ฅผ ์ฝ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}
} catch (Exception e) {
throw new IllegalArgumentException("๊ฐ•์˜ ์ปค๋ฒ„ ์ด๋ฏธ์ง€๋ฅผ ์ฝ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}

if (courseCoverImageData.getWidth() < MIN_WIDTH || courseCoverImageData.getHeight() < MIN_HEIGHT) {
throw new IllegalArgumentException("๊ฐ•์˜ ์ปค๋ฒ„ ์ด๋ฏธ์ง€๋Š” ์ตœ์†Œ 300x200 ํ”ฝ์…€ ์ด์ƒ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.");

Choose a reason for hiding this comment

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

์ด๋ฏธ์ง€ ํฌ๊ธฐ๋Š” 1MB ์ดํ•˜์—ฌ์•ผ ํ•œ๋‹ค.

๋„ ์ถ”๊ฐ€๋˜๋ฉด ์ข‹๊ฒ ๋„ค์š” ๐Ÿ˜„

}
}
}
20 changes: 20 additions & 0 deletions src/main/java/nextstep/courses/domain/CourseFree.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package nextstep.courses.domain;

import java.time.LocalDateTime;

public class CourseFree extends Course {

Choose a reason for hiding this comment

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

๋ฌด๋ฃŒ ๊ฐ•์˜๋Š” ์ตœ๋Œ€ ์ˆ˜๊ฐ• ์ธ์› ์ œํ•œ์ด ์—†๋‹ค.

๋ฌด๋ฃŒ๊ฐ•์˜๋Š” ์ตœ๋Œ€ ์ˆ˜๊ฐ• ์ธ์› ์ œํ•œ์ด ์—†๊ธฐ๋Š” ํ•˜์ง€๋งŒ Course๋Š” ์ธ์›์ด ์Œ์ˆ˜๊ฐ€ ์•„๋‹Œ 0์ด์ƒ์ด ๋˜์–ด์•ผํ•˜๋ฏ€๋กœ ๊ฒ€์ฆ ๋กœ์ง์„ ์ถ”๊ฐ€ํ•ด๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”?


public static final Long MAX_ATTENDEES = Long.MAX_VALUE;

public CourseFree(String title, Long creatorId, String courseCoverImageFilePath) {
super(title, creatorId, courseCoverImageFilePath, MAX_ATTENDEES);
}

public CourseFree(Long id, String title, Long creatorId, LocalDateTime createdAt, LocalDateTime updatedAt, String courseCoverImageFilePath) {
super(id, title, creatorId, createdAt, updatedAt, courseCoverImageFilePath, MAX_ATTENDEES, CourseStatus.PREPARING);
}

public CourseFree(Long id, String title, Long creatorId, LocalDateTime createdAt, LocalDateTime updatedAt, String courseCoverImageFilePath, CourseStatus courseStatus) {
super(id, title, creatorId, createdAt, updatedAt, courseCoverImageFilePath, MAX_ATTENDEES, courseStatus);
}
}
19 changes: 19 additions & 0 deletions src/main/java/nextstep/courses/domain/CoursePaid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package nextstep.courses.domain;

import java.time.LocalDateTime;

public class CoursePaid extends Course {

public CoursePaid(String title, Long creatorId, String courseCoverImageFilePath, Long maxAttendees) {
super(title, creatorId, courseCoverImageFilePath, maxAttendees);
}

public CoursePaid(Long id, String title, Long creatorId, LocalDateTime createdAt, LocalDateTime updatedAt, String courseCoverImageFilePath, Long maxAttendees) {
super(id, title, creatorId, createdAt, updatedAt, courseCoverImageFilePath, maxAttendees, CourseStatus.PREPARING);
}

public CoursePaid(Long id, String title, Long creatorId, LocalDateTime createdAt, LocalDateTime updatedAt, String courseCoverImageFilePath, Long maxAttendees, CourseStatus courseStatus) {
super(id, title, creatorId, createdAt, updatedAt, courseCoverImageFilePath, maxAttendees, courseStatus);
}

}
7 changes: 7 additions & 0 deletions src/main/java/nextstep/courses/domain/CourseStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package nextstep.courses.domain;

public enum CourseStatus {
PREPARING,
RECRUITING,
ENDED
}
5 changes: 5 additions & 0 deletions src/main/java/nextstep/courses/domain/Session.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package nextstep.courses.domain;

public class Session {

}
5 changes: 5 additions & 0 deletions src/main/java/nextstep/courses/domain/SessionList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package nextstep.courses.domain;

public class SessionList {

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public Course findById(Long id) {
rs.getString(2),
rs.getLong(3),
toLocalDateTime(rs.getTimestamp(4)),
toLocalDateTime(rs.getTimestamp(5)));
toLocalDateTime(rs.getTimestamp(5)),
null, // courseCoverImageFilePath
null, // maxAttendees
null // courseStatus
);
return jdbcTemplate.queryForObject(sql, rowMapper, id);
}

Expand Down
31 changes: 31 additions & 0 deletions src/main/java/nextstep/qna/domain/AnswerList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package nextstep.qna.domain;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class AnswerList implements Iterable<Answer> {

private final List<Answer> answers;

public AnswerList() {
this.answers = new ArrayList<>();
}

public AnswerList(List<Answer> answers) {
this.answers = answers;
}

public List<Answer> getAnswers() {
return answers;
}

public void add(Answer answer) {
answers.add(answer);
}

@Override
public Iterator<Answer> iterator() {
return answers.iterator();
}
}
5 changes: 3 additions & 2 deletions src/main/java/nextstep/qna/domain/Question.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class Question {

private NsUser writer;

private List<Answer> answers = new ArrayList<>();
// private List<Answer> answers = new ArrayList<>();
private AnswerList answers = new AnswerList();

private boolean deleted = false;

Expand Down Expand Up @@ -96,7 +97,7 @@ public List<DeleteHistory> delete(NsUser loginUser) throws CannotDeleteException
}

public List<Answer> getAnswers() {
return answers;
return answers.getAnswers();
}

@Override
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/nextstep/users/domain/NsUser.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package nextstep.users.domain;

import nextstep.qna.UnAuthorizedException;

import java.time.LocalDateTime;
import java.util.Objects;

import nextstep.courses.domain.Course;
import nextstep.courses.domain.CourseFree;
import nextstep.courses.domain.CoursePaid;
import nextstep.courses.domain.CourseStatus;
import nextstep.qna.UnAuthorizedException;

public class NsUser {
public static final GuestNsUser GUEST_USER = new GuestNsUser();

Expand Down Expand Up @@ -124,6 +128,22 @@ public boolean isGuestUser() {
}
}

public void registerCourse(Course course) {

Choose a reason for hiding this comment

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

NsUser ์— "func::registerCourse" ๋ฅผ ๋„ฃ์—ˆ๋Š”๋ฐ ์ด ๋ถ€๋ถ„์€ ์–ด๋–ป๊ฒŒ ํ…Œ์ŠคํŠธ๋ฅผ ํ•ด์•ผํ•˜๋Š” ๊ฒƒ์ธ๊ฐ€์š”?

๋ง์”€ํ•ด์ฃผ์‹  ๋‚ด์šฉ์„ ์ดํ•ด๋ชปํ–ˆ์–ด์š”. NsUser.registerCourse๋ฅผ ํ…Œ์ŠคํŠธํ•˜๋Š” ๊ฒƒ์€ NsUserTest์—์„œ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋ฅผ ๋งŒ๋“ค์–ด๋ณด๋ฉด ๋˜๋Š” ๊ฒƒ ์•„๋‹๊นŒ์š”?

์กฐ๊ธˆ ๋” ์ž์„ธํ•˜๊ฒŒ ๋ง์”€ํ•ด์ฃผ์‹œ๋ฉด ํ™•์ธํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค ๐Ÿ˜„

if (course.getCourseStatus() == CourseStatus.PREPARING) {
throw new IllegalArgumentException("๊ฐ•์˜๊ฐ€ ์ค€๋น„์ค‘์ž…๋‹ˆ๋‹ค.");
}
Comment on lines +132 to +134

Choose a reason for hiding this comment

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

์ด๋Ÿฐ ๋กœ์ง๋„ Course์— ๋“ค์–ด๊ฐ€๋ณด๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!

๊ฐ•์˜์— ๋Œ€ํ•œ ๊ฒ€์ฆ ์ฑ…์ž„ ์ž์ฒด๋ฅผ Course์— ๋„ฃ์–ด์ฃผ๋Š” ๊ฑธ ๊ณ ๋ คํ•ด๋ณด์‹œ๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค ๐Ÿ˜„

if (course.getAttendees().size() >= course.getMaxAttendees()) {
throw new IllegalArgumentException("๊ฐ•์˜ ์ˆ˜๊ฐ• ์ธ์›์ด ์ดˆ๊ณผ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
}
Comment on lines +135 to +137

Choose a reason for hiding this comment

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

์œ ๋ฃŒ ๊ฐ•์˜๋Š” ๊ฐ•์˜ ์ตœ๋Œ€ ์ˆ˜๊ฐ• ์ธ์›์„ ์ดˆ๊ณผํ•  ์ˆ˜ ์—†๋‹ค.

๋ˆ„๊ฐ€ ์ˆ˜๊ฐ•๋“ฑ๋ก์— ๋Œ€ํ•œ ๊ฒƒ์„ ๊ฐ€์ ธ๊ฐ€๋А๋ƒ์— ๋Œ€ํ•œ ๊ฒƒ์„ ๊ณ ๋ฏผํ•ด๋ณด๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š” ๐Ÿ˜„

"์ˆ˜๊ฐ•"์ด๋ผ๋Š” ๊ฒƒ์€ ๊ฐ•์˜์— ํšŒ์›์ด ๋“ค์–ด๊ฐ€๋Š” ๊ฒƒ์ด๋ฏ€๋กœ Course์—์„œ ์ˆ˜๊ฐ•ํ•˜๊ณ  ์žˆ๋Š” ์ธ์›์„ ๋“ค๊ณ  ์žˆ๋Š” ๊ฒƒ์ด ๋” ์ž์—ฐ์Šค๋Ÿฝ์ง€ ์•Š์„๊นŒ์š”? ๊ทธ๋Ÿผ Course.๋“ฑ๋ก()์—์„œ๋Š” ์œ ๋ฃŒ๊ฐ•์˜์ธ ๊ฒฝ์šฐ ์ด๋ฏธ ์ˆ˜๊ฐ•์ตœ๋Œ€์ธ์›์ด ๊ฐ€๋“์ฐฌ ์ผ€์ด์Šค์—์„œ ์˜ˆ์™ธ๋ฅผ ํ„ฐํŠธ๋ฆฌ๋„๋ก ํ•ด์ค„ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™๊ตฌ์š” :)

if (course instanceof CoursePaid) {
// Payment...
course.getAttendees().add(this);
}
if (course instanceof CourseFree) {
course.getAttendees().add(this);
}
}

@Override
public String toString() {
return "NsUser{" +
Expand Down
Loading