From f89ccf979351b28e6f12eb08554170039b622926 Mon Sep 17 00:00:00 2001 From: ming Date: Tue, 29 Oct 2024 01:16:45 +0900 Subject: [PATCH 01/23] =?UTF-8?q?refactor:=201=EB=8B=A8=EA=B3=84=20?= =?UTF-8?q?=ED=94=BC=EB=93=9C=EB=B0=B1=20=EB=B0=98=EC=98=81=20-=20?= =?UTF-8?q?=EB=B6=88=ED=95=84=EC=9A=94=20setDeleted=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/nextstep/qna/domain/Answer.java | 2 +- src/main/java/nextstep/qna/domain/Question.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/nextstep/qna/domain/Answer.java b/src/main/java/nextstep/qna/domain/Answer.java index 4ed8dba7e0..dd3f60e907 100644 --- a/src/main/java/nextstep/qna/domain/Answer.java +++ b/src/main/java/nextstep/qna/domain/Answer.java @@ -75,7 +75,7 @@ public void toQuestion(Question question) { } public DeleteHistory delete() { - this.setDeleted(true); + deleted = true; return new DeleteHistory(ContentType.ANSWER, this.id, this.writer, LocalDateTime.now()); } diff --git a/src/main/java/nextstep/qna/domain/Question.java b/src/main/java/nextstep/qna/domain/Question.java index 3c0c8c6017..bb6ee3e6ee 100644 --- a/src/main/java/nextstep/qna/domain/Question.java +++ b/src/main/java/nextstep/qna/domain/Question.java @@ -105,7 +105,7 @@ public List delete(NsUser loginUser) throws CannotDeleteException checkDeletePermission(loginUser); List deleteHistories = new ArrayList<>(); - this.setDeleted(true); + deleted = true; deleteHistories.add(new DeleteHistory(ContentType.QUESTION, this.id, this.writer, LocalDateTime.now())); deleteHistories.addAll(deleteAnswers()); return deleteHistories; From 372331ef87e97ae146d035c3620825cde20e12c7 Mon Sep 17 00:00:00 2001 From: ming Date: Tue, 29 Oct 2024 01:26:09 +0900 Subject: [PATCH 02/23] =?UTF-8?q?refactor:=201=EB=8B=A8=EA=B3=84=20?= =?UTF-8?q?=ED=94=BC=EB=93=9C=EB=B0=B1=20=EB=B0=98=EC=98=81=20-=20DeleteHi?= =?UTF-8?q?story=20=EC=83=9D=EC=84=B1=EC=9E=90=EA=B0=80=20=EC=95=84?= =?UTF-8?q?=EB=8B=8C=20=EC=A0=95=EC=A0=81=20=ED=8C=A9=ED=86=A0=EB=A6=AC=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=EB=A1=9C=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/nextstep/qna/domain/Answer.java | 2 +- src/main/java/nextstep/qna/domain/DeleteHistory.java | 9 +++++++++ src/main/java/nextstep/qna/domain/Question.java | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/nextstep/qna/domain/Answer.java b/src/main/java/nextstep/qna/domain/Answer.java index dd3f60e907..24dce6b30e 100644 --- a/src/main/java/nextstep/qna/domain/Answer.java +++ b/src/main/java/nextstep/qna/domain/Answer.java @@ -76,7 +76,7 @@ public void toQuestion(Question question) { public DeleteHistory delete() { deleted = true; - return new DeleteHistory(ContentType.ANSWER, this.id, this.writer, LocalDateTime.now()); + return DeleteHistory.createAnswerDeleteHistory(this.id, this.writer, createdDate); } @Override diff --git a/src/main/java/nextstep/qna/domain/DeleteHistory.java b/src/main/java/nextstep/qna/domain/DeleteHistory.java index 43c37e5e5c..ce789b5987 100644 --- a/src/main/java/nextstep/qna/domain/DeleteHistory.java +++ b/src/main/java/nextstep/qna/domain/DeleteHistory.java @@ -26,6 +26,15 @@ public DeleteHistory(ContentType contentType, Long contentId, NsUser deletedBy, this.createdDate = createdDate; } + public static DeleteHistory createAnswerDeleteHistory(Long contentId, NsUser deletedBy, LocalDateTime createdDate){ + return new DeleteHistory(ContentType.ANSWER, contentId, deletedBy, createdDate); + } + + + public static DeleteHistory createQuestionDeleteHistory(Long contentId, NsUser deletedBy, LocalDateTime createdDate){ + return new DeleteHistory(ContentType.QUESTION, contentId, deletedBy, createdDate); + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/main/java/nextstep/qna/domain/Question.java b/src/main/java/nextstep/qna/domain/Question.java index bb6ee3e6ee..47a7d05dc8 100644 --- a/src/main/java/nextstep/qna/domain/Question.java +++ b/src/main/java/nextstep/qna/domain/Question.java @@ -106,7 +106,7 @@ public List delete(NsUser loginUser) throws CannotDeleteException List deleteHistories = new ArrayList<>(); deleted = true; - deleteHistories.add(new DeleteHistory(ContentType.QUESTION, this.id, this.writer, LocalDateTime.now())); + deleteHistories.add(DeleteHistory.createQuestionDeleteHistory(this.id, this.writer, createdDate)); deleteHistories.addAll(deleteAnswers()); return deleteHistories; } From 8928f60fece398c211d5da24169434f4fe5aa731 Mon Sep 17 00:00:00 2001 From: ming Date: Tue, 29 Oct 2024 01:29:13 +0900 Subject: [PATCH 03/23] =?UTF-8?q?chore:=20=EB=B6=88=ED=95=84=EC=9A=94=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/nextstep/qna/domain/Answer.java | 11 --------- .../java/nextstep/qna/domain/Question.java | 23 ------------------- 2 files changed, 34 deletions(-) diff --git a/src/main/java/nextstep/qna/domain/Answer.java b/src/main/java/nextstep/qna/domain/Answer.java index 24dce6b30e..43fcf0c121 100644 --- a/src/main/java/nextstep/qna/domain/Answer.java +++ b/src/main/java/nextstep/qna/domain/Answer.java @@ -2,10 +2,8 @@ import nextstep.qna.NotFoundException; import nextstep.qna.UnAuthorizedException; -import nextstep.qna.service.DeleteHistoryService; import nextstep.users.domain.NsUser; -import javax.annotation.Resource; import java.time.LocalDateTime; public class Answer { @@ -49,11 +47,6 @@ public Long getId() { return id; } - public Answer setDeleted(boolean deleted) { - this.deleted = deleted; - return this; - } - public boolean isDeleted() { return deleted; } @@ -66,10 +59,6 @@ public NsUser getWriter() { return writer; } - public String getContents() { - return contents; - } - public void toQuestion(Question question) { this.question = question; } diff --git a/src/main/java/nextstep/qna/domain/Question.java b/src/main/java/nextstep/qna/domain/Question.java index 47a7d05dc8..cd9685a131 100644 --- a/src/main/java/nextstep/qna/domain/Question.java +++ b/src/main/java/nextstep/qna/domain/Question.java @@ -42,24 +42,6 @@ public Long getId() { return id; } - public String getTitle() { - return title; - } - - public Question setTitle(String title) { - this.title = title; - return this; - } - - public String getContents() { - return contents; - } - - public Question setContents(String contents) { - this.contents = contents; - return this; - } - public NsUser getWriter() { return writer; } @@ -92,11 +74,6 @@ public void checkAnswerOwner(Answer answer, NsUser loginUser) throws CannotDelet } } - public Question setDeleted(boolean deleted) { - this.deleted = deleted; - return this; - } - public boolean isDeleted() { return deleted; } From d965af3516a02788e6fcb26e09093645216938e3 Mon Sep 17 00:00:00 2001 From: ming Date: Tue, 29 Oct 2024 01:30:40 +0900 Subject: [PATCH 04/23] =?UTF-8?q?docs:=20=EB=B6=88=ED=95=84=EC=9A=94=20TOD?= =?UTF-8?q?O=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 688fcda86d..3c630947a7 100644 --- a/README.md +++ b/README.md @@ -36,11 +36,8 @@ Question - [x] answer에 다른 사람 답변이 있는 경우 - [x] 질문 삭제 - [x] 질문 삭제 - - [ ] 질문 삭제 이력 기록 - - [ ] 모든 답변 삭제 Answer - [x] 작성자 본인인지 확인 - [x] 답변 삭제 - - [x] 답변 삭제 - - [ ] 답변 삭제 이력 기록 \ No newline at end of file + - [x] 답변 삭제 \ No newline at end of file From a22f18e961d9986ef9ff76f61aac483be252de3b Mon Sep 17 00:00:00 2001 From: ming Date: Tue, 29 Oct 2024 01:52:18 +0900 Subject: [PATCH 05/23] =?UTF-8?q?refactor:=201=EB=8B=A8=EA=B3=84=20?= =?UTF-8?q?=ED=94=BC=EB=93=9C=EB=B0=B1=20=EB=B0=98=EC=98=81=20-=20Answers?= =?UTF-8?q?=20=EC=9D=BC=EA=B8=89=EC=BB=AC=EB=A0=89=EC=85=98=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC,=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/nextstep/qna/domain/Answers.java | 36 +++++++++++++++++ .../java/nextstep/qna/domain/Question.java | 39 ++++++------------- .../nextstep/qna/domain/QuestionTest.java | 6 +-- 3 files changed, 49 insertions(+), 32 deletions(-) create mode 100644 src/main/java/nextstep/qna/domain/Answers.java diff --git a/src/main/java/nextstep/qna/domain/Answers.java b/src/main/java/nextstep/qna/domain/Answers.java new file mode 100644 index 0000000000..364382818f --- /dev/null +++ b/src/main/java/nextstep/qna/domain/Answers.java @@ -0,0 +1,36 @@ +package nextstep.qna.domain; + +import nextstep.qna.CannotDeleteException; +import nextstep.users.domain.NsUser; + +import java.util.ArrayList; +import java.util.List; + +public class Answers { + + private List answers = new ArrayList<>(); + + public void checkDeletePermission(NsUser loginUser) throws CannotDeleteException { + for (Answer answer : this.answers) { + checkAnswerOwner(answer, loginUser); + } + } + + private void checkAnswerOwner(Answer answer, NsUser loginUser) throws CannotDeleteException { + if (!answer.isOwner(loginUser)) { + throw new CannotDeleteException("다른 사람이 쓴 답변이 있어 삭제할 수 없습니다."); + } + } + + public void add(Answer answer){ + this.answers.add(answer); + } + + public List deleteAnswers() { + List deleteHistories = new ArrayList<>(); + for (Answer answer : answers) { + deleteHistories.add(answer.delete()); + } + return deleteHistories; + } +} diff --git a/src/main/java/nextstep/qna/domain/Question.java b/src/main/java/nextstep/qna/domain/Question.java index cd9685a131..2a90f190ce 100644 --- a/src/main/java/nextstep/qna/domain/Question.java +++ b/src/main/java/nextstep/qna/domain/Question.java @@ -16,7 +16,7 @@ public class Question { private NsUser writer; - private List answers = new ArrayList<>(); + private Answers answers; private boolean deleted = false; @@ -25,6 +25,7 @@ public class Question { private LocalDateTime updatedDate; public Question() { + this(null, null, null, null); } public Question(NsUser writer, String title, String contents) { @@ -36,6 +37,7 @@ public Question(Long id, NsUser writer, String title, String contents) { this.writer = writer; this.title = title; this.contents = contents; + this.answers = new Answers(); } public Long getId() { @@ -48,51 +50,32 @@ public NsUser getWriter() { public void addAnswer(Answer answer) { answer.toQuestion(this); - answers.add(answer); + this.answers.add(answer); } private boolean isOwner(NsUser loginUser) { return writer.equals(loginUser); } + public boolean isDeleted() { + return deleted; + } + public void checkDeletePermission(NsUser loginUser) throws CannotDeleteException { if (!this.isOwner(loginUser)) { throw new CannotDeleteException("질문을 삭제할 권한이 없습니다."); } - for (Answer answer : this.answers) { - checkAnswerOwner(answer, loginUser); - } + this.answers.checkDeletePermission(loginUser); } - //todo owner가 맞는지 체크하는 로직은 Answer에 있어야 할 것 같은데, - // Exception 문구를 보면 Question에 있어야할 내용 같아서 이곳에 작성함. - - // 테스트만 아니면 public으로 작성할 필요가 없을 것 같아 고민됨. - public void checkAnswerOwner(Answer answer, NsUser loginUser) throws CannotDeleteException { - if (!answer.isOwner(loginUser)) { - throw new CannotDeleteException("다른 사람이 쓴 답변이 있어 삭제할 수 없습니다."); - } - } - - public boolean isDeleted() { - return deleted; - } public List delete(NsUser loginUser) throws CannotDeleteException { checkDeletePermission(loginUser); - List deleteHistories = new ArrayList<>(); deleted = true; - deleteHistories.add(DeleteHistory.createQuestionDeleteHistory(this.id, this.writer, createdDate)); - deleteHistories.addAll(deleteAnswers()); - return deleteHistories; - } - - private List deleteAnswers() { List deleteHistories = new ArrayList<>(); - for (Answer answer : answers) { - deleteHistories.add(answer.delete()); - } + deleteHistories.add(DeleteHistory.createQuestionDeleteHistory(this.id, this.writer, createdDate)); + deleteHistories.addAll(this.answers.deleteAnswers()); return deleteHistories; } diff --git a/src/test/java/nextstep/qna/domain/QuestionTest.java b/src/test/java/nextstep/qna/domain/QuestionTest.java index b9934bb646..9fc23ffc68 100644 --- a/src/test/java/nextstep/qna/domain/QuestionTest.java +++ b/src/test/java/nextstep/qna/domain/QuestionTest.java @@ -20,11 +20,9 @@ public class QuestionTest { @Test void 질문_삭제_권한없음__다른_사람_답변_존재(){ + Q1.addAnswer(new Answer(NsUserTest.JAVAJIGI, QuestionTest.Q1, "Answers Contents1")); assertThatThrownBy(() -> { - Q1.checkAnswerOwner( - new Answer(NsUserTest.JAVAJIGI, QuestionTest.Q1, "Answers Contents1"), - NsUserTest.SANJIGI - ); + Q1.checkDeletePermission(NsUserTest.SANJIGI); }).isInstanceOf(CannotDeleteException.class); } From e9340bddb8ad8314733793bec149abee8de1dadc Mon Sep 17 00:00:00 2001 From: ming Date: Wed, 30 Oct 2024 22:10:17 +0900 Subject: [PATCH 06/23] =?UTF-8?q?refactor:=20QuestionBody=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/nextstep/qna/domain/Question.java | 12 +++--------- .../java/nextstep/qna/domain/QuestionBody.java | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 src/main/java/nextstep/qna/domain/QuestionBody.java diff --git a/src/main/java/nextstep/qna/domain/Question.java b/src/main/java/nextstep/qna/domain/Question.java index 2a90f190ce..4bb99699af 100644 --- a/src/main/java/nextstep/qna/domain/Question.java +++ b/src/main/java/nextstep/qna/domain/Question.java @@ -9,11 +9,7 @@ public class Question { private Long id; - - private String title; - - private String contents; - + private QuestionBody questionBody; private NsUser writer; private Answers answers; @@ -35,8 +31,7 @@ public Question(NsUser writer, String title, String contents) { public Question(Long id, NsUser writer, String title, String contents) { this.id = id; this.writer = writer; - this.title = title; - this.contents = contents; + this.questionBody = new QuestionBody(title, contents); this.answers = new Answers(); } @@ -68,7 +63,6 @@ public void checkDeletePermission(NsUser loginUser) throws CannotDeleteException this.answers.checkDeletePermission(loginUser); } - public List delete(NsUser loginUser) throws CannotDeleteException { checkDeletePermission(loginUser); @@ -81,6 +75,6 @@ public List delete(NsUser loginUser) throws CannotDeleteException @Override public String toString() { - return "Question [id=" + getId() + ", title=" + title + ", contents=" + contents + ", writer=" + writer + "]"; + return "Question [id=" + getId() + ", " + questionBody.toString() + " writer=" + writer + "]"; } } diff --git a/src/main/java/nextstep/qna/domain/QuestionBody.java b/src/main/java/nextstep/qna/domain/QuestionBody.java new file mode 100644 index 0000000000..6ffbc3f7cc --- /dev/null +++ b/src/main/java/nextstep/qna/domain/QuestionBody.java @@ -0,0 +1,18 @@ +package nextstep.qna.domain; + +public class QuestionBody { + + private String title; + private String contents; + + public QuestionBody(String title, String contents){ + this.title = title; + this.contents = contents; + } + + @Override + public String toString() { + return "title='" + title + '\'' + + ", contents='" + contents; + } +} From 1ec08ae1a882f03f6dd4880b0c773610d5ee0f8a Mon Sep 17 00:00:00 2001 From: ming Date: Wed, 30 Oct 2024 22:17:46 +0900 Subject: [PATCH 07/23] =?UTF-8?q?refactor:=20Deleted=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/nextstep/qna/domain/Answer.java | 7 ++++--- src/main/java/nextstep/qna/domain/Deleted.java | 14 ++++++++++++++ src/main/java/nextstep/qna/domain/Question.java | 7 ++++--- 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 src/main/java/nextstep/qna/domain/Deleted.java diff --git a/src/main/java/nextstep/qna/domain/Answer.java b/src/main/java/nextstep/qna/domain/Answer.java index 43fcf0c121..6c8b1e8622 100644 --- a/src/main/java/nextstep/qna/domain/Answer.java +++ b/src/main/java/nextstep/qna/domain/Answer.java @@ -15,7 +15,7 @@ public class Answer { private String contents; - private boolean deleted = false; + private Deleted deleted; private LocalDateTime createdDate = LocalDateTime.now(); @@ -41,6 +41,7 @@ public Answer(Long id, NsUser writer, Question question, String contents) { this.writer = writer; this.question = question; this.contents = contents; + this.deleted = new Deleted(); } public Long getId() { @@ -48,7 +49,7 @@ public Long getId() { } public boolean isDeleted() { - return deleted; + return this.deleted.isDeleted(); } public boolean isOwner(NsUser writer) { @@ -64,7 +65,7 @@ public void toQuestion(Question question) { } public DeleteHistory delete() { - deleted = true; + this.deleted.setDeleted(true); return DeleteHistory.createAnswerDeleteHistory(this.id, this.writer, createdDate); } diff --git a/src/main/java/nextstep/qna/domain/Deleted.java b/src/main/java/nextstep/qna/domain/Deleted.java new file mode 100644 index 0000000000..0aebb1a5ac --- /dev/null +++ b/src/main/java/nextstep/qna/domain/Deleted.java @@ -0,0 +1,14 @@ +package nextstep.qna.domain; + +public class Deleted { + private boolean deleted = false; + + public boolean isDeleted() { + return deleted; + } + + public void setDeleted(Boolean deleted){ + this.deleted = deleted; + } + +} diff --git a/src/main/java/nextstep/qna/domain/Question.java b/src/main/java/nextstep/qna/domain/Question.java index 4bb99699af..8abee3a6bd 100644 --- a/src/main/java/nextstep/qna/domain/Question.java +++ b/src/main/java/nextstep/qna/domain/Question.java @@ -14,7 +14,7 @@ public class Question { private Answers answers; - private boolean deleted = false; + private Deleted deleted; private LocalDateTime createdDate = LocalDateTime.now(); @@ -33,6 +33,7 @@ public Question(Long id, NsUser writer, String title, String contents) { this.writer = writer; this.questionBody = new QuestionBody(title, contents); this.answers = new Answers(); + this.deleted = new Deleted(); } public Long getId() { @@ -53,7 +54,7 @@ private boolean isOwner(NsUser loginUser) { } public boolean isDeleted() { - return deleted; + return deleted.isDeleted(); } public void checkDeletePermission(NsUser loginUser) throws CannotDeleteException { @@ -66,7 +67,7 @@ public void checkDeletePermission(NsUser loginUser) throws CannotDeleteException public List delete(NsUser loginUser) throws CannotDeleteException { checkDeletePermission(loginUser); - deleted = true; + deleted.setDeleted(true); List deleteHistories = new ArrayList<>(); deleteHistories.add(DeleteHistory.createQuestionDeleteHistory(this.id, this.writer, createdDate)); deleteHistories.addAll(this.answers.deleteAnswers()); From f320b7bf18cb8865bdc62824b47746f66fd9bb7d Mon Sep 17 00:00:00 2001 From: ming Date: Thu, 31 Oct 2024 02:07:20 +0900 Subject: [PATCH 08/23] =?UTF-8?q?docs:=202=EB=8B=A8=EA=B3=84=20-=20?= =?UTF-8?q?=EC=88=98=EA=B0=95=EC=8B=A0=EC=B2=AD=20TODO=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c630947a7..ac08a08b87 100644 --- a/README.md +++ b/README.md @@ -40,4 +40,59 @@ Question Answer - [x] 작성자 본인인지 확인 - [x] 답변 삭제 - - [x] 답변 삭제 \ No newline at end of file + - [x] 답변 삭제 + +--- + +### 수강 신청 기능 요구사항 +과정(Course)은 기수 단위로 운영하며, 여러 개의 강의(Session)를 가질 수 있다. +강의는 시작일과 종료일을 가진다. +강의는 강의 커버 이미지 정보를 가진다. +이미지 크기는 1MB 이하여야 한다. +이미지 타입은 gif, jpg(jpeg 포함),, png, svg만 허용한다. +이미지의 width는 300픽셀, height는 200픽셀 이상이어야 하며, width와 height의 비율은 3:2여야 한다. +강의는 무료 강의와 유료 강의로 나뉜다. +무료 강의는 최대 수강 인원 제한이 없다. +유료 강의는 강의 최대 수강 인원을 초과할 수 없다. +유료 강의는 수강생이 결제한 금액과 수강료가 일치할 때 수강 신청이 가능하다. +강의 상태는 준비중, 모집중, 종료 3가지 상태를 가진다. +강의 수강신청은 강의 상태가 모집중일 때만 가능하다. +유료 강의의 경우 결제는 이미 완료한 것으로 가정하고 이후 과정을 구현한다. +결제를 완료한 결제 정보는 payments 모듈을 통해 관리되며, 결제 정보는 Payment 객체에 담겨 반환된다. + +### TODO +- [ ] Course + - List + + +- [ ] Session + - 시작일, 종료일 + - 커버 이미지 정보 + - 무료/유료 + - 강의 상태 + + +- [ ] 커버 이미지 정보 + - gif, jpg, jpeg, png, svg만 허용 + - width >= 300, height >= 200 / width * 2 = height * 3 + + +- [ ] 무료 강의 + - 최대 수강 인원 제한 없음 + +- [ ] 유료 강의 + - 강의 최대 수강인원 + - 강의 최대 수강인원 초과 불가 + - 수강료 + - 수강생이 결제한 금액 == 수강료 일 때만 수강신청 가능 + + +- [ ] 강의 상태 + - 준비중(Preparing)/모집중(Recruiting)/종료(Closed) + - 모집중일 때만 신청 가능 + + +- [ ] Payments + - 결제 완료 List + +- [ ] Payment \ No newline at end of file From e379e60bece7cafbbefede73f40e24884590deb0 Mon Sep 17 00:00:00 2001 From: ming Date: Thu, 31 Oct 2024 02:07:53 +0900 Subject: [PATCH 09/23] =?UTF-8?q?feat:=202=EB=8B=A8=EA=B3=84=20-=20?= =?UTF-8?q?=EC=88=98=EA=B0=95=EC=8B=A0=EC=B2=AD=20=EA=B0=95=EC=9D=98=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=20=EB=8F=84=EB=A9=94=EC=9D=B8=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nextstep/courses/domain/SessionStatus.java | 12 ++++++++++++ .../infrastructure/SessionStatusTest.java | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/main/java/nextstep/courses/domain/SessionStatus.java create mode 100644 src/test/java/nextstep/courses/infrastructure/SessionStatusTest.java diff --git a/src/main/java/nextstep/courses/domain/SessionStatus.java b/src/main/java/nextstep/courses/domain/SessionStatus.java new file mode 100644 index 0000000000..9e0fd9a4c7 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/SessionStatus.java @@ -0,0 +1,12 @@ +package nextstep.courses.domain; + +public enum SessionStatus { + + PREPARING, + RECRUITING, + CLOSED; + + public boolean isRecruiting(){ + return this == RECRUITING; + } +} diff --git a/src/test/java/nextstep/courses/infrastructure/SessionStatusTest.java b/src/test/java/nextstep/courses/infrastructure/SessionStatusTest.java new file mode 100644 index 0000000000..873a0405f0 --- /dev/null +++ b/src/test/java/nextstep/courses/infrastructure/SessionStatusTest.java @@ -0,0 +1,17 @@ +package nextstep.courses.infrastructure; + +import nextstep.courses.domain.SessionStatus; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SessionStatusTest { + + @Test + @DisplayName("강의 상태가 모집중일 때만 신청이 가능하다.") + void 강의_상태_모집중(){ + SessionStatus sessionStatus = SessionStatus.RECRUITING; + assertTrue(sessionStatus.isRecruiting()); + } +} From 8311e79a3532b6f239c785303700e2ceee332869 Mon Sep 17 00:00:00 2001 From: ming Date: Thu, 31 Oct 2024 02:28:36 +0900 Subject: [PATCH 10/23] =?UTF-8?q?test:=202=EB=8B=A8=EA=B3=84=20-=20?= =?UTF-8?q?=EC=88=98=EA=B0=95=EC=8B=A0=EC=B2=AD=20=EA=B0=95=EC=9D=98=20?= =?UTF-8?q?=EB=8F=84=EB=A9=94=EC=9D=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- .../java/nextstep/courses/domain/Session.java | 20 +++++++++ .../courses/infrastructure/SessionTest.java | 43 +++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 src/main/java/nextstep/courses/domain/Session.java create mode 100644 src/test/java/nextstep/courses/infrastructure/SessionTest.java diff --git a/README.md b/README.md index ac08a08b87..f07683c8ce 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ Answer - [ ] Session - 시작일, 종료일 - 커버 이미지 정보 - - 무료/유료 + - 강의 유형(무료/유료) - 강의 상태 @@ -87,7 +87,7 @@ Answer - 수강생이 결제한 금액 == 수강료 일 때만 수강신청 가능 -- [ ] 강의 상태 +- [x] 강의 상태 - 준비중(Preparing)/모집중(Recruiting)/종료(Closed) - 모집중일 때만 신청 가능 diff --git a/src/main/java/nextstep/courses/domain/Session.java b/src/main/java/nextstep/courses/domain/Session.java new file mode 100644 index 0000000000..a302df08b4 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/Session.java @@ -0,0 +1,20 @@ +package nextstep.courses.domain; + +public class Session { + + public boolean isValidCoverImage() { + return false; + } + public boolean canEnroll() { + return false; + } + private boolean isFull() { + return false; + } + private boolean isTuitionPaid() { + return false; + } + private boolean isRecruiting() { + return false; + } +} diff --git a/src/test/java/nextstep/courses/infrastructure/SessionTest.java b/src/test/java/nextstep/courses/infrastructure/SessionTest.java new file mode 100644 index 0000000000..36709cf243 --- /dev/null +++ b/src/test/java/nextstep/courses/infrastructure/SessionTest.java @@ -0,0 +1,43 @@ +package nextstep.courses.infrastructure; + +import nextstep.courses.domain.Session; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SessionTest { + + private Session session; + + @BeforeEach + void setUp() { + session = new Session(); + } + + @Test + void 커버_이미지_확인() { + assertTrue(session.isValidCoverImage()); + } + + @Test + void 수강신청_가능여부_확인__인원초과_확인() { +// session.setEnrollmentCount(0); +// assertTrue(session.isFull()); + assertTrue(session.canEnroll()); + } + + @Test + void 수강신청_가능여부_확인__강의_수강료_확인() { +// session.setTuitionFee(20000); +// assertTrue(session.isTuitionPaid(20000)); //수강생이 결제한 금액 + assertTrue(session.canEnroll()); + } + + @Test + void 수강신청_가능여부_확인__강의_상태_모집중() { +// assertTrue(session.isRecruiting()); + assertTrue(session.canEnroll()); + } + +} From c3837de60cc810efaa499adea443b56385bad6b0 Mon Sep 17 00:00:00 2001 From: ming Date: Thu, 31 Oct 2024 02:32:41 +0900 Subject: [PATCH 11/23] =?UTF-8?q?test:=202=EB=8B=A8=EA=B3=84=20-=20?= =?UTF-8?q?=EC=88=98=EA=B0=95=EC=8B=A0=EC=B2=AD=20=EA=B0=95=EC=9D=98=20?= =?UTF-8?q?=EC=BB=A4=EB=B2=84=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nextstep/courses/domain/SessionCoverImage.java | 7 +++++++ .../infrastructure/SessionCoverImageTest.java | 13 +++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/main/java/nextstep/courses/domain/SessionCoverImage.java create mode 100644 src/test/java/nextstep/courses/infrastructure/SessionCoverImageTest.java diff --git a/src/main/java/nextstep/courses/domain/SessionCoverImage.java b/src/main/java/nextstep/courses/domain/SessionCoverImage.java new file mode 100644 index 0000000000..55d5306d1e --- /dev/null +++ b/src/main/java/nextstep/courses/domain/SessionCoverImage.java @@ -0,0 +1,7 @@ +package nextstep.courses.domain; + +public class SessionCoverImage { + public boolean isValidCoverImage() { + return false; + } +} diff --git a/src/test/java/nextstep/courses/infrastructure/SessionCoverImageTest.java b/src/test/java/nextstep/courses/infrastructure/SessionCoverImageTest.java new file mode 100644 index 0000000000..ab4529a812 --- /dev/null +++ b/src/test/java/nextstep/courses/infrastructure/SessionCoverImageTest.java @@ -0,0 +1,13 @@ +package nextstep.courses.infrastructure; + +import nextstep.courses.domain.SessionCoverImage; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; +public class SessionCoverImageTest { + @Test + void 커버_이미지_확인(){ + SessionCoverImage sessionCoverImage = new SessionCoverImage(); + assertTrue(sessionCoverImage.isValidCoverImage()); + } +} From 6a0964e53dd13f9141b76b5f2e14b6aa78a25c7c Mon Sep 17 00:00:00 2001 From: ming Date: Thu, 31 Oct 2024 02:41:02 +0900 Subject: [PATCH 12/23] =?UTF-8?q?feat:=202=EB=8B=A8=EA=B3=84=20-=20?= =?UTF-8?q?=EC=88=98=EA=B0=95=EC=8B=A0=EC=B2=AD=20=EA=B0=95=EC=9D=98=20?= =?UTF-8?q?=EC=BB=A4=EB=B2=84=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- .../courses/domain/SessionCoverImage.java | 20 +++++++++++++++- .../infrastructure/SessionCoverImageTest.java | 23 ++++++++++++++++--- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f07683c8ce..98acf18c12 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Answer - 강의 상태 -- [ ] 커버 이미지 정보 +- [x] 커버 이미지 정보 - gif, jpg, jpeg, png, svg만 허용 - width >= 300, height >= 200 / width * 2 = height * 3 diff --git a/src/main/java/nextstep/courses/domain/SessionCoverImage.java b/src/main/java/nextstep/courses/domain/SessionCoverImage.java index 55d5306d1e..5704151ab5 100644 --- a/src/main/java/nextstep/courses/domain/SessionCoverImage.java +++ b/src/main/java/nextstep/courses/domain/SessionCoverImage.java @@ -1,7 +1,25 @@ package nextstep.courses.domain; +import java.util.Arrays; + public class SessionCoverImage { + private String extension; + private int width; + private int height; + + public SessionCoverImage(String extension, int width, int height){ + this.extension = extension; + this.width = width; + this.height = height; + } + public boolean isValidCoverImage() { - return false; + if(!Arrays.asList("gif","jpg", "jpeg", "png", "svg").contains(extension)) { + return false; + } + if(width < 300 || height < 200 || width * 2 != height * 3) { + return false; + } + return true; } } diff --git a/src/test/java/nextstep/courses/infrastructure/SessionCoverImageTest.java b/src/test/java/nextstep/courses/infrastructure/SessionCoverImageTest.java index ab4529a812..a09c3d541c 100644 --- a/src/test/java/nextstep/courses/infrastructure/SessionCoverImageTest.java +++ b/src/test/java/nextstep/courses/infrastructure/SessionCoverImageTest.java @@ -3,11 +3,28 @@ import nextstep.courses.domain.SessionCoverImage; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; public class SessionCoverImageTest { @Test - void 커버_이미지_확인(){ - SessionCoverImage sessionCoverImage = new SessionCoverImage(); - assertTrue(sessionCoverImage.isValidCoverImage()); + void 커버_이미지_확인__유효한_이미지(){ + SessionCoverImage image1 = new SessionCoverImage("gif", 300, 200); + assertTrue(image1.isValidCoverImage()); + } + + @Test + void 커버_이미지_확인__유효하지_않은_확장자(){ + SessionCoverImage image2 = new SessionCoverImage("bmp", 300, 200); + assertFalse(image2.isValidCoverImage()); + } + + @Test + void 커버_이미지_확인__유효하지_않은_이미지_사이즈(){ + SessionCoverImage image1 = new SessionCoverImage("gif", 200, 200); + assertFalse(image1.isValidCoverImage()); + SessionCoverImage image2 = new SessionCoverImage("gif", 300, 300); + assertFalse(image2.isValidCoverImage()); + SessionCoverImage image3 = new SessionCoverImage("gif", 300, 400); + assertFalse(image3.isValidCoverImage()); } } From bcae477be8b41f8a170c670d874f0e59262f3367 Mon Sep 17 00:00:00 2001 From: ming Date: Thu, 31 Oct 2024 03:28:50 +0900 Subject: [PATCH 13/23] =?UTF-8?q?feat:=202=EB=8B=A8=EA=B3=84=20-=20?= =?UTF-8?q?=EC=88=98=EA=B0=95=EC=8B=A0=EC=B2=AD=20=EA=B0=95=EC=9D=98=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20=EB=B0=8F=20?= =?UTF-8?q?=EB=8F=84=EB=A9=94=EC=9D=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++-- .../nextstep/courses/domain/FreeSession.java | 8 +++++ .../nextstep/courses/domain/PaidSession.java | 29 ++++++++++++++++ .../java/nextstep/courses/domain/Session.java | 34 ++++++++++++++----- .../courses/domain/SessionStrategy.java | 6 ++++ .../courses/infrastructure/SessionTest.java | 26 +++++++------- 6 files changed, 85 insertions(+), 24 deletions(-) create mode 100644 src/main/java/nextstep/courses/domain/FreeSession.java create mode 100644 src/main/java/nextstep/courses/domain/PaidSession.java create mode 100644 src/main/java/nextstep/courses/domain/SessionStrategy.java diff --git a/README.md b/README.md index 98acf18c12..f9cdb693a1 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ Answer - List -- [ ] Session +- [x] Session - 시작일, 종료일 - 커버 이미지 정보 - 강의 유형(무료/유료) @@ -77,10 +77,10 @@ Answer - width >= 300, height >= 200 / width * 2 = height * 3 -- [ ] 무료 강의 +- [x] 무료 강의 - 최대 수강 인원 제한 없음 -- [ ] 유료 강의 +- [x] 유료 강의 - 강의 최대 수강인원 - 강의 최대 수강인원 초과 불가 - 수강료 diff --git a/src/main/java/nextstep/courses/domain/FreeSession.java b/src/main/java/nextstep/courses/domain/FreeSession.java new file mode 100644 index 0000000000..c8047a8bd3 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/FreeSession.java @@ -0,0 +1,8 @@ +package nextstep.courses.domain; + +public class FreeSession implements SessionStrategy { + @Override + public boolean canEnroll() { + return true; + } +} diff --git a/src/main/java/nextstep/courses/domain/PaidSession.java b/src/main/java/nextstep/courses/domain/PaidSession.java new file mode 100644 index 0000000000..45a914a45b --- /dev/null +++ b/src/main/java/nextstep/courses/domain/PaidSession.java @@ -0,0 +1,29 @@ +package nextstep.courses.domain; + +public class PaidSession implements SessionStrategy { + + private int maxEnrollmentCount; + private int currentEnrollmentCount; + private int tuitionFee; + + private int paymentAmount; //todo + + public PaidSession(int maxEnrollmentCount, int currentEnrollmentCount, int tuitionFee, int paymentAmount){ + this.maxEnrollmentCount = maxEnrollmentCount; + this.currentEnrollmentCount = currentEnrollmentCount; + this.tuitionFee = tuitionFee; + this.paymentAmount = paymentAmount; + } + + private boolean isFull() { + return maxEnrollmentCount <= currentEnrollmentCount; + } + private boolean isTuitionPaid() { + return tuitionFee == paymentAmount; + } + + @Override + public boolean canEnroll() { + return !isFull() && isTuitionPaid(); //todo + } +} diff --git a/src/main/java/nextstep/courses/domain/Session.java b/src/main/java/nextstep/courses/domain/Session.java index a302df08b4..a4cfe5e1d1 100644 --- a/src/main/java/nextstep/courses/domain/Session.java +++ b/src/main/java/nextstep/courses/domain/Session.java @@ -1,20 +1,36 @@ package nextstep.courses.domain; +import java.time.LocalDate; + public class Session { - public boolean isValidCoverImage() { - return false; + private LocalDate startDate; + private LocalDate endDate; + private SessionCoverImage sessionCoverImage; + private SessionStatus sessionStatus; + private SessionStrategy sessionTypeStrategy; + + public Session(SessionCoverImage sessionCoverImage, SessionStatus sessionStatus, SessionStrategy sessionTypeStrategy) { + this(null, null, sessionCoverImage, sessionStatus, sessionTypeStrategy); } - public boolean canEnroll() { - return false; + + public Session(LocalDate startDate, LocalDate endDate, SessionCoverImage sessionCoverImage, SessionStatus sessionStatus, SessionStrategy sessionTypeStrategy) { + this.startDate = startDate; + this.endDate = endDate; + this.sessionCoverImage = sessionCoverImage; + this.sessionStatus = sessionStatus; + this.sessionTypeStrategy = sessionTypeStrategy; } - private boolean isFull() { - return false; + + public boolean isValidCoverImage() { + return sessionCoverImage.isValidCoverImage(); } - private boolean isTuitionPaid() { - return false; + + public boolean canEnroll() { + return sessionTypeStrategy.canEnroll() && isRecruiting(); } + private boolean isRecruiting() { - return false; + return sessionStatus.isRecruiting(); } } diff --git a/src/main/java/nextstep/courses/domain/SessionStrategy.java b/src/main/java/nextstep/courses/domain/SessionStrategy.java new file mode 100644 index 0000000000..da91d4c0a1 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/SessionStrategy.java @@ -0,0 +1,6 @@ +package nextstep.courses.domain; + +@FunctionalInterface +public interface SessionStrategy { + boolean canEnroll(); +} diff --git a/src/test/java/nextstep/courses/infrastructure/SessionTest.java b/src/test/java/nextstep/courses/infrastructure/SessionTest.java index 36709cf243..43f0e0c66b 100644 --- a/src/test/java/nextstep/courses/infrastructure/SessionTest.java +++ b/src/test/java/nextstep/courses/infrastructure/SessionTest.java @@ -1,43 +1,45 @@ package nextstep.courses.infrastructure; -import nextstep.courses.domain.Session; -import org.junit.jupiter.api.BeforeEach; +import nextstep.courses.domain.*; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; public class SessionTest { private Session session; - @BeforeEach - void setUp() { - session = new Session(); - } - @Test void 커버_이미지_확인() { + session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, () -> true); assertTrue(session.isValidCoverImage()); } @Test void 수강신청_가능여부_확인__인원초과_확인() { -// session.setEnrollmentCount(0); -// assertTrue(session.isFull()); + session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, new PaidSession(3, 2, 20000, 20000)); assertTrue(session.canEnroll()); + session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, new PaidSession(2, 2, 20000, 20000)); + assertFalse(session.canEnroll()); } @Test void 수강신청_가능여부_확인__강의_수강료_확인() { -// session.setTuitionFee(20000); -// assertTrue(session.isTuitionPaid(20000)); //수강생이 결제한 금액 + session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, new PaidSession(3, 2, 20000, 20000)); assertTrue(session.canEnroll()); + session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, new PaidSession(3, 2, 20000, 15000)); + assertFalse(session.canEnroll()); } @Test void 수강신청_가능여부_확인__강의_상태_모집중() { -// assertTrue(session.isRecruiting()); + session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, () -> true); assertTrue(session.canEnroll()); + session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.CLOSED, new FreeSession()); + assertFalse(session.canEnroll()); + session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.CLOSED, new PaidSession(3, 2, 20000, 20000)); + assertFalse(session.canEnroll()); } } From dcea3851faa7b948bcfc728a219aa3df2713c387 Mon Sep 17 00:00:00 2001 From: ming Date: Thu, 31 Oct 2024 03:35:18 +0900 Subject: [PATCH 14/23] =?UTF-8?q?feat:=202=EB=8B=A8=EA=B3=84=20-=20?= =?UTF-8?q?=EC=88=98=EA=B0=95=EC=8B=A0=EC=B2=AD=20=EA=B0=95=EC=9D=98=20?= =?UTF-8?q?=EC=9C=A0=EB=A3=8C=EA=B0=95=EC=9D=98=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructure/PaidSessionTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/test/java/nextstep/courses/infrastructure/PaidSessionTest.java diff --git a/src/test/java/nextstep/courses/infrastructure/PaidSessionTest.java b/src/test/java/nextstep/courses/infrastructure/PaidSessionTest.java new file mode 100644 index 0000000000..a85911b7b3 --- /dev/null +++ b/src/test/java/nextstep/courses/infrastructure/PaidSessionTest.java @@ -0,0 +1,29 @@ +package nextstep.courses.infrastructure; + +import nextstep.courses.domain.PaidSession; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class PaidSessionTest { + + private PaidSession paidSession; + + @Test + void 수강신청_가능여부_확인__강의_수강료_확인() { + paidSession = new PaidSession(3, 2, 20000, 20000); + assertTrue(paidSession.canEnroll()); + paidSession = new PaidSession(3, 2, 20000, 15000); + } + + @Test + void 수강신청_가능여부_확인__인원초과_확인() { + + paidSession = new PaidSession(3, 2, 20000, 20000); + assertTrue(paidSession.canEnroll()); + paidSession = new PaidSession(2, 2, 20000, 20000); + assertFalse(paidSession.canEnroll()); + } + +} From 3423226ce161993ba14d32768d9c33a6a530fdf7 Mon Sep 17 00:00:00 2001 From: mslee Date: Thu, 31 Oct 2024 12:26:32 +0900 Subject: [PATCH 15/23] =?UTF-8?q?feat:=202=EB=8B=A8=EA=B3=84=20-=20?= =?UTF-8?q?=EC=88=98=EA=B0=95=EC=8B=A0=EC=B2=AD=20=EC=BD=94=EC=8A=A4?= =?UTF-8?q?=EC=97=90=20=EA=B0=95=EC=9D=98=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- src/main/java/nextstep/courses/domain/Course.java | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f9cdb693a1..395b81c19b 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Answer 강의는 시작일과 종료일을 가진다. 강의는 강의 커버 이미지 정보를 가진다. 이미지 크기는 1MB 이하여야 한다. -이미지 타입은 gif, jpg(jpeg 포함),, png, svg만 허용한다. +이미지 타입은 gif, jpg(jpeg 포함), png, svg만 허용한다. 이미지의 width는 300픽셀, height는 200픽셀 이상이어야 하며, width와 height의 비율은 3:2여야 한다. 강의는 무료 강의와 유료 강의로 나뉜다. 무료 강의는 최대 수강 인원 제한이 없다. @@ -61,7 +61,7 @@ Answer 결제를 완료한 결제 정보는 payments 모듈을 통해 관리되며, 결제 정보는 Payment 객체에 담겨 반환된다. ### TODO -- [ ] Course +- [x] Course - List diff --git a/src/main/java/nextstep/courses/domain/Course.java b/src/main/java/nextstep/courses/domain/Course.java index 0f69716043..0864465842 100644 --- a/src/main/java/nextstep/courses/domain/Course.java +++ b/src/main/java/nextstep/courses/domain/Course.java @@ -1,6 +1,8 @@ package nextstep.courses.domain; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; public class Course { private Long id; @@ -13,19 +15,26 @@ public class Course { private LocalDateTime updatedAt; + private List sessions; + public Course() { } public Course(String title, Long creatorId) { - this(0L, title, creatorId, LocalDateTime.now(), null); + this(0L, title, creatorId, LocalDateTime.now(), null, new ArrayList<>()); } public Course(Long id, String title, Long creatorId, LocalDateTime createdAt, LocalDateTime updatedAt) { + this(id, title, creatorId, createdAt, updatedAt, new ArrayList<>()); + } + + public Course(Long id, String title, Long creatorId, LocalDateTime createdAt, LocalDateTime updatedAt, List sessions) { this.id = id; this.title = title; this.creatorId = creatorId; this.createdAt = createdAt; this.updatedAt = updatedAt; + this.sessions = sessions; } public String getTitle() { From 2a433512e48e518f1c5086e6c315c440ff3655fb Mon Sep 17 00:00:00 2001 From: ming Date: Thu, 31 Oct 2024 17:49:12 +0900 Subject: [PATCH 16/23] =?UTF-8?q?feat:=202=EB=8B=A8=EA=B3=84=20-=20Course?= =?UTF-8?q?=20=EA=B8=B0=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + src/main/java/nextstep/courses/domain/Course.java | 2 ++ 2 files changed, 3 insertions(+) diff --git a/README.md b/README.md index 395b81c19b..4e610b8d18 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ Answer ### TODO - [x] Course + - 기수 - List diff --git a/src/main/java/nextstep/courses/domain/Course.java b/src/main/java/nextstep/courses/domain/Course.java index 0864465842..e925e13fae 100644 --- a/src/main/java/nextstep/courses/domain/Course.java +++ b/src/main/java/nextstep/courses/domain/Course.java @@ -15,6 +15,8 @@ public class Course { private LocalDateTime updatedAt; + private int batchNumber; + private List sessions; public Course() { From 82675be570a087298fdbe45169efd6982ae87114 Mon Sep 17 00:00:00 2001 From: ming Date: Thu, 31 Oct 2024 18:13:28 +0900 Subject: [PATCH 17/23] =?UTF-8?q?feat:=202=EB=8B=A8=EA=B3=84=20-=20Session?= =?UTF-8?q?Strategy=20=EC=88=98=EC=A0=95,=20PaidSession=20List=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 ++--- .../nextstep/courses/domain/FreeSession.java | 4 ++- .../nextstep/courses/domain/PaidSession.java | 24 +++++++++----- .../java/nextstep/courses/domain/Session.java | 17 +++++----- .../courses/domain/SessionStrategy.java | 4 ++- .../nextstep/payments/domain/Payment.java | 8 +++++ .../infrastructure/FreeSessionTest.java | 18 +++++++++++ .../infrastructure/PaidSessionTest.java | 16 +++++----- .../courses/infrastructure/SessionTest.java | 31 ++++++++++--------- 9 files changed, 86 insertions(+), 43 deletions(-) create mode 100644 src/test/java/nextstep/courses/infrastructure/FreeSessionTest.java diff --git a/README.md b/README.md index 4e610b8d18..c492c1a287 100644 --- a/README.md +++ b/README.md @@ -86,14 +86,11 @@ Answer - 강의 최대 수강인원 초과 불가 - 수강료 - 수강생이 결제한 금액 == 수강료 일 때만 수강신청 가능 - + - 결제 완료 List - [x] 강의 상태 - 준비중(Preparing)/모집중(Recruiting)/종료(Closed) - 모집중일 때만 신청 가능 - - [ ] Payments - - 결제 완료 List - -- [ ] Payment \ No newline at end of file + - List \ No newline at end of file diff --git a/src/main/java/nextstep/courses/domain/FreeSession.java b/src/main/java/nextstep/courses/domain/FreeSession.java index c8047a8bd3..6abc8c247a 100644 --- a/src/main/java/nextstep/courses/domain/FreeSession.java +++ b/src/main/java/nextstep/courses/domain/FreeSession.java @@ -1,8 +1,10 @@ package nextstep.courses.domain; +import nextstep.payments.domain.Payment; + public class FreeSession implements SessionStrategy { @Override - public boolean canEnroll() { + public boolean canEnroll(Payment payment) { return true; } } diff --git a/src/main/java/nextstep/courses/domain/PaidSession.java b/src/main/java/nextstep/courses/domain/PaidSession.java index 45a914a45b..3fa97d10b9 100644 --- a/src/main/java/nextstep/courses/domain/PaidSession.java +++ b/src/main/java/nextstep/courses/domain/PaidSession.java @@ -1,29 +1,37 @@ package nextstep.courses.domain; +import nextstep.payments.domain.Payment; + +import java.util.ArrayList; +import java.util.List; + public class PaidSession implements SessionStrategy { private int maxEnrollmentCount; private int currentEnrollmentCount; private int tuitionFee; - private int paymentAmount; //todo + private List payments; - public PaidSession(int maxEnrollmentCount, int currentEnrollmentCount, int tuitionFee, int paymentAmount){ + public PaidSession(int maxEnrollmentCount, int currentEnrollmentCount, int tuitionFee){ this.maxEnrollmentCount = maxEnrollmentCount; this.currentEnrollmentCount = currentEnrollmentCount; this.tuitionFee = tuitionFee; - this.paymentAmount = paymentAmount; + this.payments = new ArrayList<>(); } private boolean isFull() { return maxEnrollmentCount <= currentEnrollmentCount; } - private boolean isTuitionPaid() { - return tuitionFee == paymentAmount; - } @Override - public boolean canEnroll() { - return !isFull() && isTuitionPaid(); //todo + public boolean canEnroll(Payment payment) { + return !isFull() && payment.isTuitionPaid(tuitionFee); //todo + } + + public void enroll(Payment payment){ + if(canEnroll(payment)){ + payments.add(payment); + } } } diff --git a/src/main/java/nextstep/courses/domain/Session.java b/src/main/java/nextstep/courses/domain/Session.java index a4cfe5e1d1..a231f77b8d 100644 --- a/src/main/java/nextstep/courses/domain/Session.java +++ b/src/main/java/nextstep/courses/domain/Session.java @@ -1,6 +1,9 @@ package nextstep.courses.domain; +import nextstep.payments.domain.Payment; + import java.time.LocalDate; +import java.util.List; public class Session { @@ -8,26 +11,26 @@ public class Session { private LocalDate endDate; private SessionCoverImage sessionCoverImage; private SessionStatus sessionStatus; - private SessionStrategy sessionTypeStrategy; + private SessionStrategy sessionStrategy; - public Session(SessionCoverImage sessionCoverImage, SessionStatus sessionStatus, SessionStrategy sessionTypeStrategy) { - this(null, null, sessionCoverImage, sessionStatus, sessionTypeStrategy); + public Session(SessionCoverImage sessionCoverImage, SessionStatus sessionStatus, SessionStrategy sessionStrategy) { + this(null, null, sessionCoverImage, sessionStatus, sessionStrategy); } - public Session(LocalDate startDate, LocalDate endDate, SessionCoverImage sessionCoverImage, SessionStatus sessionStatus, SessionStrategy sessionTypeStrategy) { + public Session(LocalDate startDate, LocalDate endDate, SessionCoverImage sessionCoverImage, SessionStatus sessionStatus, SessionStrategy sessionStrategy) { this.startDate = startDate; this.endDate = endDate; this.sessionCoverImage = sessionCoverImage; this.sessionStatus = sessionStatus; - this.sessionTypeStrategy = sessionTypeStrategy; + this.sessionStrategy = sessionStrategy; } public boolean isValidCoverImage() { return sessionCoverImage.isValidCoverImage(); } - public boolean canEnroll() { - return sessionTypeStrategy.canEnroll() && isRecruiting(); + public boolean canEnroll(Payment payment) { + return sessionStrategy.canEnroll(payment) && isRecruiting(); } private boolean isRecruiting() { diff --git a/src/main/java/nextstep/courses/domain/SessionStrategy.java b/src/main/java/nextstep/courses/domain/SessionStrategy.java index da91d4c0a1..92f15b45b4 100644 --- a/src/main/java/nextstep/courses/domain/SessionStrategy.java +++ b/src/main/java/nextstep/courses/domain/SessionStrategy.java @@ -1,6 +1,8 @@ package nextstep.courses.domain; +import nextstep.payments.domain.Payment; + @FunctionalInterface public interface SessionStrategy { - boolean canEnroll(); + boolean canEnroll(Payment payment); } diff --git a/src/main/java/nextstep/payments/domain/Payment.java b/src/main/java/nextstep/payments/domain/Payment.java index 57d833f851..db2f651042 100644 --- a/src/main/java/nextstep/payments/domain/Payment.java +++ b/src/main/java/nextstep/payments/domain/Payment.java @@ -19,6 +19,10 @@ public class Payment { public Payment() { } + public Payment(Long amount) { + this(null, null, null, amount); + } + public Payment(String id, Long sessionId, Long nsUserId, Long amount) { this.id = id; this.sessionId = sessionId; @@ -26,4 +30,8 @@ public Payment(String id, Long sessionId, Long nsUserId, Long amount) { this.amount = amount; this.createdAt = LocalDateTime.now(); } + + public boolean isTuitionPaid(int tuitionFee) { + return tuitionFee == amount; + } } diff --git a/src/test/java/nextstep/courses/infrastructure/FreeSessionTest.java b/src/test/java/nextstep/courses/infrastructure/FreeSessionTest.java new file mode 100644 index 0000000000..f46111c2ff --- /dev/null +++ b/src/test/java/nextstep/courses/infrastructure/FreeSessionTest.java @@ -0,0 +1,18 @@ +package nextstep.courses.infrastructure; + +import nextstep.courses.domain.FreeSession; +import nextstep.payments.domain.Payment; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class FreeSessionTest { + + private FreeSession freeSession; + + @Test + void 수강신청_가능여부_확인() { + freeSession = new FreeSession(); + assertTrue(freeSession.canEnroll(new Payment(0L))); + } +} diff --git a/src/test/java/nextstep/courses/infrastructure/PaidSessionTest.java b/src/test/java/nextstep/courses/infrastructure/PaidSessionTest.java index a85911b7b3..38eb2628c9 100644 --- a/src/test/java/nextstep/courses/infrastructure/PaidSessionTest.java +++ b/src/test/java/nextstep/courses/infrastructure/PaidSessionTest.java @@ -1,6 +1,7 @@ package nextstep.courses.infrastructure; import nextstep.courses.domain.PaidSession; +import nextstep.payments.domain.Payment; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -12,18 +13,19 @@ public class PaidSessionTest { @Test void 수강신청_가능여부_확인__강의_수강료_확인() { - paidSession = new PaidSession(3, 2, 20000, 20000); - assertTrue(paidSession.canEnroll()); - paidSession = new PaidSession(3, 2, 20000, 15000); + paidSession = new PaidSession(3, 2, 20000); + assertTrue(paidSession.canEnroll(new Payment(20000L))); + paidSession = new PaidSession(3, 2, 20000); + assertFalse(paidSession.canEnroll(new Payment(15000L))); } @Test void 수강신청_가능여부_확인__인원초과_확인() { - paidSession = new PaidSession(3, 2, 20000, 20000); - assertTrue(paidSession.canEnroll()); - paidSession = new PaidSession(2, 2, 20000, 20000); - assertFalse(paidSession.canEnroll()); + paidSession = new PaidSession(3, 2, 20000); + assertTrue(paidSession.canEnroll(new Payment(20000L))); + paidSession = new PaidSession(2, 2, 20000); + assertFalse(paidSession.canEnroll(new Payment(20000L))); } } diff --git a/src/test/java/nextstep/courses/infrastructure/SessionTest.java b/src/test/java/nextstep/courses/infrastructure/SessionTest.java index 43f0e0c66b..72102a1a3d 100644 --- a/src/test/java/nextstep/courses/infrastructure/SessionTest.java +++ b/src/test/java/nextstep/courses/infrastructure/SessionTest.java @@ -1,6 +1,7 @@ package nextstep.courses.infrastructure; import nextstep.courses.domain.*; +import nextstep.payments.domain.Payment; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -12,34 +13,36 @@ public class SessionTest { @Test void 커버_이미지_확인() { - session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, () -> true); + session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, (payment) -> true); assertTrue(session.isValidCoverImage()); } @Test void 수강신청_가능여부_확인__인원초과_확인() { - session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, new PaidSession(3, 2, 20000, 20000)); - assertTrue(session.canEnroll()); - session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, new PaidSession(2, 2, 20000, 20000)); - assertFalse(session.canEnroll()); + session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, new PaidSession(3, 2, 20000)); + assertTrue(session.canEnroll(new Payment(20000L))); + session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, new PaidSession(2, 2, 20000)); + assertFalse(session.canEnroll(new Payment(20000L))); } @Test void 수강신청_가능여부_확인__강의_수강료_확인() { - session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, new PaidSession(3, 2, 20000, 20000)); - assertTrue(session.canEnroll()); - session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, new PaidSession(3, 2, 20000, 15000)); - assertFalse(session.canEnroll()); + session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, new PaidSession(3, 2, 20000)); + assertTrue(session.canEnroll(new Payment(20000L))); + session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, new PaidSession(3, 2, 20000)); + assertFalse(session.canEnroll(new Payment(15000L))); } @Test void 수강신청_가능여부_확인__강의_상태_모집중() { - session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, () -> true); - assertTrue(session.canEnroll()); + session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, (payment) -> true); + assertTrue(session.canEnroll(new Payment(20000L))); + session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.CLOSED, new FreeSession()); - assertFalse(session.canEnroll()); - session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.CLOSED, new PaidSession(3, 2, 20000, 20000)); - assertFalse(session.canEnroll()); + assertFalse(session.canEnroll(new Payment(0L))); + + session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.CLOSED, new PaidSession(3, 2, 20000)); + assertFalse(session.canEnroll(new Payment(20000L))); } } From f787e170ec52c77a439961d1e73ae00f4f0fd0f8 Mon Sep 17 00:00:00 2001 From: ming Date: Thu, 31 Oct 2024 18:20:15 +0900 Subject: [PATCH 18/23] =?UTF-8?q?feat:=202=EB=8B=A8=EA=B3=84=20-=20Payment?= =?UTF-8?q?s=20=EC=9D=BC=EA=B8=89=EC=BB=AC=EB=A0=89=EC=85=98=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- .../nextstep/courses/domain/PaidSession.java | 17 +++++++---------- .../java/nextstep/courses/domain/Payments.java | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 src/main/java/nextstep/courses/domain/Payments.java diff --git a/README.md b/README.md index c492c1a287..6bed6f9327 100644 --- a/README.md +++ b/README.md @@ -92,5 +92,5 @@ Answer - 준비중(Preparing)/모집중(Recruiting)/종료(Closed) - 모집중일 때만 신청 가능 -- [ ] Payments +- [x] Payments - List \ No newline at end of file diff --git a/src/main/java/nextstep/courses/domain/PaidSession.java b/src/main/java/nextstep/courses/domain/PaidSession.java index 3fa97d10b9..e30b9c30e4 100644 --- a/src/main/java/nextstep/courses/domain/PaidSession.java +++ b/src/main/java/nextstep/courses/domain/PaidSession.java @@ -2,36 +2,33 @@ import nextstep.payments.domain.Payment; -import java.util.ArrayList; -import java.util.List; - public class PaidSession implements SessionStrategy { private int maxEnrollmentCount; private int currentEnrollmentCount; private int tuitionFee; - private List payments; + private Payments payments; public PaidSession(int maxEnrollmentCount, int currentEnrollmentCount, int tuitionFee){ this.maxEnrollmentCount = maxEnrollmentCount; this.currentEnrollmentCount = currentEnrollmentCount; this.tuitionFee = tuitionFee; - this.payments = new ArrayList<>(); + this.payments = new Payments(); } private boolean isFull() { return maxEnrollmentCount <= currentEnrollmentCount; } - @Override - public boolean canEnroll(Payment payment) { - return !isFull() && payment.isTuitionPaid(tuitionFee); //todo - } - public void enroll(Payment payment){ if(canEnroll(payment)){ payments.add(payment); } } + + @Override + public boolean canEnroll(Payment payment) { + return !isFull() && payment.isTuitionPaid(tuitionFee); + } } diff --git a/src/main/java/nextstep/courses/domain/Payments.java b/src/main/java/nextstep/courses/domain/Payments.java new file mode 100644 index 0000000000..9fecf01ea2 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/Payments.java @@ -0,0 +1,14 @@ +package nextstep.courses.domain; + +import nextstep.payments.domain.Payment; + +import java.util.ArrayList; +import java.util.List; + +public class Payments { + private List values = new ArrayList<>(); + + public void add(Payment payment){ + values.add(payment); + } +} From 26e958f93d6385771aed19a7c578ef86f6eb1502 Mon Sep 17 00:00:00 2001 From: ming Date: Thu, 31 Oct 2024 18:45:52 +0900 Subject: [PATCH 19/23] =?UTF-8?q?feat:=202=EB=8B=A8=EA=B3=84=20-=20Session?= =?UTF-8?q?s=20=EC=9D=BC=EA=B8=89=EC=BB=AC=EB=A0=89=EC=85=98=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ src/main/java/nextstep/courses/domain/Course.java | 13 ++++++------- src/main/java/nextstep/courses/domain/Sessions.java | 7 +++++++ 3 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 src/main/java/nextstep/courses/domain/Sessions.java diff --git a/README.md b/README.md index 6bed6f9327..d19a827b69 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ Answer - 기수 - List +- [x] Sessions + - List - [x] Session - 시작일, 종료일 diff --git a/src/main/java/nextstep/courses/domain/Course.java b/src/main/java/nextstep/courses/domain/Course.java index e925e13fae..25f0914fa3 100644 --- a/src/main/java/nextstep/courses/domain/Course.java +++ b/src/main/java/nextstep/courses/domain/Course.java @@ -1,8 +1,6 @@ package nextstep.courses.domain; import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; public class Course { private Long id; @@ -15,27 +13,28 @@ public class Course { private LocalDateTime updatedAt; - private int batchNumber; + private Integer batchNumber; - private List sessions; + private Sessions sessions; public Course() { } public Course(String title, Long creatorId) { - this(0L, title, creatorId, LocalDateTime.now(), null, new ArrayList<>()); + this(0L, title, creatorId, LocalDateTime.now(), null, null, new Sessions()); } public Course(Long id, String title, Long creatorId, LocalDateTime createdAt, LocalDateTime updatedAt) { - this(id, title, creatorId, createdAt, updatedAt, new ArrayList<>()); + this(id, title, creatorId, createdAt, updatedAt, null, new Sessions()); } - public Course(Long id, String title, Long creatorId, LocalDateTime createdAt, LocalDateTime updatedAt, List sessions) { + public Course(Long id, String title, Long creatorId, LocalDateTime createdAt, LocalDateTime updatedAt, Integer batchNumber, Sessions sessions) { this.id = id; this.title = title; this.creatorId = creatorId; this.createdAt = createdAt; this.updatedAt = updatedAt; + this.batchNumber = batchNumber; this.sessions = sessions; } diff --git a/src/main/java/nextstep/courses/domain/Sessions.java b/src/main/java/nextstep/courses/domain/Sessions.java new file mode 100644 index 0000000000..7b958e3b55 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/Sessions.java @@ -0,0 +1,7 @@ +package nextstep.courses.domain; + +import java.util.List; + +public class Sessions { + private List values; +} From cf831803557555aedb68bad7ce62065dfcc79026 Mon Sep 17 00:00:00 2001 From: ming Date: Thu, 31 Oct 2024 18:53:38 +0900 Subject: [PATCH 20/23] =?UTF-8?q?feat:=202=EB=8B=A8=EA=B3=84=20-=20Session?= =?UTF-8?q?Date=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../courses/domain/session/SessionDate.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/main/java/nextstep/courses/domain/session/SessionDate.java diff --git a/src/main/java/nextstep/courses/domain/session/SessionDate.java b/src/main/java/nextstep/courses/domain/session/SessionDate.java new file mode 100644 index 0000000000..581deb8fbd --- /dev/null +++ b/src/main/java/nextstep/courses/domain/session/SessionDate.java @@ -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; + } +} From 6355517167286e48e1a61fca540d74300fbcc3a8 Mon Sep 17 00:00:00 2001 From: ming Date: Thu, 31 Oct 2024 18:54:26 +0900 Subject: [PATCH 21/23] =?UTF-8?q?feat:=202=EB=8B=A8=EA=B3=84=20-=20session?= =?UTF-8?q?=20=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=B6=94=EA=B0=80,=20Payments?= =?UTF-8?q?=20payments=20=ED=8C=A8=ED=82=A4=EC=A7=80=EB=A1=9C=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 33 +++++++++---------- .../java/nextstep/courses/domain/Course.java | 2 ++ .../domain/{ => session}/FreeSession.java | 2 +- .../domain/{ => session}/PaidSession.java | 5 +-- .../courses/domain/{ => session}/Session.java | 9 ++--- .../{ => session}/SessionCoverImage.java | 2 +- .../domain/{ => session}/SessionStatus.java | 2 +- .../domain/{ => session}/SessionStrategy.java | 2 +- .../domain/{ => session}/Sessions.java | 2 +- .../domain/Payments.java | 4 +-- .../infrastructure/FreeSessionTest.java | 2 +- .../infrastructure/PaidSessionTest.java | 2 +- .../infrastructure/SessionCoverImageTest.java | 2 +- .../infrastructure/SessionStatusTest.java | 2 +- .../courses/infrastructure/SessionTest.java | 2 +- 15 files changed, 35 insertions(+), 38 deletions(-) rename src/main/java/nextstep/courses/domain/{ => session}/FreeSession.java (82%) rename src/main/java/nextstep/courses/domain/{ => session}/PaidSession.java (86%) rename src/main/java/nextstep/courses/domain/{ => session}/Session.java (84%) rename src/main/java/nextstep/courses/domain/{ => session}/SessionCoverImage.java (93%) rename src/main/java/nextstep/courses/domain/{ => session}/SessionStatus.java (78%) rename src/main/java/nextstep/courses/domain/{ => session}/SessionStrategy.java (77%) rename src/main/java/nextstep/courses/domain/{ => session}/Sessions.java (67%) rename src/main/java/nextstep/{courses => payments}/domain/Payments.java (73%) diff --git a/README.md b/README.md index d19a827b69..0080372732 100644 --- a/README.md +++ b/README.md @@ -45,20 +45,21 @@ Answer --- ### 수강 신청 기능 요구사항 -과정(Course)은 기수 단위로 운영하며, 여러 개의 강의(Session)를 가질 수 있다. -강의는 시작일과 종료일을 가진다. -강의는 강의 커버 이미지 정보를 가진다. -이미지 크기는 1MB 이하여야 한다. -이미지 타입은 gif, jpg(jpeg 포함), png, svg만 허용한다. -이미지의 width는 300픽셀, height는 200픽셀 이상이어야 하며, width와 height의 비율은 3:2여야 한다. -강의는 무료 강의와 유료 강의로 나뉜다. -무료 강의는 최대 수강 인원 제한이 없다. -유료 강의는 강의 최대 수강 인원을 초과할 수 없다. -유료 강의는 수강생이 결제한 금액과 수강료가 일치할 때 수강 신청이 가능하다. -강의 상태는 준비중, 모집중, 종료 3가지 상태를 가진다. -강의 수강신청은 강의 상태가 모집중일 때만 가능하다. -유료 강의의 경우 결제는 이미 완료한 것으로 가정하고 이후 과정을 구현한다. -결제를 완료한 결제 정보는 payments 모듈을 통해 관리되며, 결제 정보는 Payment 객체에 담겨 반환된다. +- [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] 유료 강의는 수강생이 결제한 금액과 수강료가 일치할 때 수강 신청이 가능하다. +- [x] 강의 상태는 준비중, 모집중, 종료 3가지 상태를 가진다. +- [x] 강의 수강신청은 강의 상태가 모집중일 때만 가능하다. + +- [x] 유료 강의의 경우 결제는 이미 완료한 것으로 가정하고 이후 과정을 구현한다. +- [x] 결제를 완료한 결제 정보는 payments 모듈을 통해 관리되며, 결제 정보는 Payment 객체에 담겨 반환된다. ### TODO - [x] Course @@ -69,17 +70,15 @@ Answer - List - [x] Session - - 시작일, 종료일 + - SessionData(시작일, 종료일) - 커버 이미지 정보 - 강의 유형(무료/유료) - 강의 상태 - - [x] 커버 이미지 정보 - gif, jpg, jpeg, png, svg만 허용 - width >= 300, height >= 200 / width * 2 = height * 3 - - [x] 무료 강의 - 최대 수강 인원 제한 없음 diff --git a/src/main/java/nextstep/courses/domain/Course.java b/src/main/java/nextstep/courses/domain/Course.java index 25f0914fa3..a591dc0fb0 100644 --- a/src/main/java/nextstep/courses/domain/Course.java +++ b/src/main/java/nextstep/courses/domain/Course.java @@ -1,5 +1,7 @@ package nextstep.courses.domain; +import nextstep.courses.domain.session.Sessions; + import java.time.LocalDateTime; public class Course { diff --git a/src/main/java/nextstep/courses/domain/FreeSession.java b/src/main/java/nextstep/courses/domain/session/FreeSession.java similarity index 82% rename from src/main/java/nextstep/courses/domain/FreeSession.java rename to src/main/java/nextstep/courses/domain/session/FreeSession.java index 6abc8c247a..4518eb22c5 100644 --- a/src/main/java/nextstep/courses/domain/FreeSession.java +++ b/src/main/java/nextstep/courses/domain/session/FreeSession.java @@ -1,4 +1,4 @@ -package nextstep.courses.domain; +package nextstep.courses.domain.session; import nextstep.payments.domain.Payment; diff --git a/src/main/java/nextstep/courses/domain/PaidSession.java b/src/main/java/nextstep/courses/domain/session/PaidSession.java similarity index 86% rename from src/main/java/nextstep/courses/domain/PaidSession.java rename to src/main/java/nextstep/courses/domain/session/PaidSession.java index e30b9c30e4..599a81823c 100644 --- a/src/main/java/nextstep/courses/domain/PaidSession.java +++ b/src/main/java/nextstep/courses/domain/session/PaidSession.java @@ -1,5 +1,6 @@ -package nextstep.courses.domain; +package nextstep.courses.domain.session; +import nextstep.payments.domain.Payments; import nextstep.payments.domain.Payment; public class PaidSession implements SessionStrategy { @@ -21,7 +22,7 @@ private boolean isFull() { return maxEnrollmentCount <= currentEnrollmentCount; } - public void enroll(Payment payment){ + public void enroll(Payment payment){ //todo if(canEnroll(payment)){ payments.add(payment); } diff --git a/src/main/java/nextstep/courses/domain/Session.java b/src/main/java/nextstep/courses/domain/session/Session.java similarity index 84% rename from src/main/java/nextstep/courses/domain/Session.java rename to src/main/java/nextstep/courses/domain/session/Session.java index a231f77b8d..90638470b4 100644 --- a/src/main/java/nextstep/courses/domain/Session.java +++ b/src/main/java/nextstep/courses/domain/session/Session.java @@ -1,14 +1,12 @@ -package nextstep.courses.domain; +package nextstep.courses.domain.session; import nextstep.payments.domain.Payment; import java.time.LocalDate; -import java.util.List; public class Session { - private LocalDate startDate; - private LocalDate endDate; + private SessionDate sessionDate; private SessionCoverImage sessionCoverImage; private SessionStatus sessionStatus; private SessionStrategy sessionStrategy; @@ -18,8 +16,7 @@ public Session(SessionCoverImage sessionCoverImage, SessionStatus sessionStatus, } public Session(LocalDate startDate, LocalDate endDate, SessionCoverImage sessionCoverImage, SessionStatus sessionStatus, SessionStrategy sessionStrategy) { - this.startDate = startDate; - this.endDate = endDate; + this.sessionDate = new SessionDate(startDate, endDate); this.sessionCoverImage = sessionCoverImage; this.sessionStatus = sessionStatus; this.sessionStrategy = sessionStrategy; diff --git a/src/main/java/nextstep/courses/domain/SessionCoverImage.java b/src/main/java/nextstep/courses/domain/session/SessionCoverImage.java similarity index 93% rename from src/main/java/nextstep/courses/domain/SessionCoverImage.java rename to src/main/java/nextstep/courses/domain/session/SessionCoverImage.java index 5704151ab5..e1349090ea 100644 --- a/src/main/java/nextstep/courses/domain/SessionCoverImage.java +++ b/src/main/java/nextstep/courses/domain/session/SessionCoverImage.java @@ -1,4 +1,4 @@ -package nextstep.courses.domain; +package nextstep.courses.domain.session; import java.util.Arrays; diff --git a/src/main/java/nextstep/courses/domain/SessionStatus.java b/src/main/java/nextstep/courses/domain/session/SessionStatus.java similarity index 78% rename from src/main/java/nextstep/courses/domain/SessionStatus.java rename to src/main/java/nextstep/courses/domain/session/SessionStatus.java index 9e0fd9a4c7..c8ff6e5710 100644 --- a/src/main/java/nextstep/courses/domain/SessionStatus.java +++ b/src/main/java/nextstep/courses/domain/session/SessionStatus.java @@ -1,4 +1,4 @@ -package nextstep.courses.domain; +package nextstep.courses.domain.session; public enum SessionStatus { diff --git a/src/main/java/nextstep/courses/domain/SessionStrategy.java b/src/main/java/nextstep/courses/domain/session/SessionStrategy.java similarity index 77% rename from src/main/java/nextstep/courses/domain/SessionStrategy.java rename to src/main/java/nextstep/courses/domain/session/SessionStrategy.java index 92f15b45b4..0388301a0c 100644 --- a/src/main/java/nextstep/courses/domain/SessionStrategy.java +++ b/src/main/java/nextstep/courses/domain/session/SessionStrategy.java @@ -1,4 +1,4 @@ -package nextstep.courses.domain; +package nextstep.courses.domain.session; import nextstep.payments.domain.Payment; diff --git a/src/main/java/nextstep/courses/domain/Sessions.java b/src/main/java/nextstep/courses/domain/session/Sessions.java similarity index 67% rename from src/main/java/nextstep/courses/domain/Sessions.java rename to src/main/java/nextstep/courses/domain/session/Sessions.java index 7b958e3b55..ec563f2eba 100644 --- a/src/main/java/nextstep/courses/domain/Sessions.java +++ b/src/main/java/nextstep/courses/domain/session/Sessions.java @@ -1,4 +1,4 @@ -package nextstep.courses.domain; +package nextstep.courses.domain.session; import java.util.List; diff --git a/src/main/java/nextstep/courses/domain/Payments.java b/src/main/java/nextstep/payments/domain/Payments.java similarity index 73% rename from src/main/java/nextstep/courses/domain/Payments.java rename to src/main/java/nextstep/payments/domain/Payments.java index 9fecf01ea2..297365d799 100644 --- a/src/main/java/nextstep/courses/domain/Payments.java +++ b/src/main/java/nextstep/payments/domain/Payments.java @@ -1,6 +1,4 @@ -package nextstep.courses.domain; - -import nextstep.payments.domain.Payment; +package nextstep.payments.domain; import java.util.ArrayList; import java.util.List; diff --git a/src/test/java/nextstep/courses/infrastructure/FreeSessionTest.java b/src/test/java/nextstep/courses/infrastructure/FreeSessionTest.java index f46111c2ff..94101721a3 100644 --- a/src/test/java/nextstep/courses/infrastructure/FreeSessionTest.java +++ b/src/test/java/nextstep/courses/infrastructure/FreeSessionTest.java @@ -1,6 +1,6 @@ package nextstep.courses.infrastructure; -import nextstep.courses.domain.FreeSession; +import nextstep.courses.domain.session.FreeSession; import nextstep.payments.domain.Payment; import org.junit.jupiter.api.Test; diff --git a/src/test/java/nextstep/courses/infrastructure/PaidSessionTest.java b/src/test/java/nextstep/courses/infrastructure/PaidSessionTest.java index 38eb2628c9..2127266429 100644 --- a/src/test/java/nextstep/courses/infrastructure/PaidSessionTest.java +++ b/src/test/java/nextstep/courses/infrastructure/PaidSessionTest.java @@ -1,6 +1,6 @@ package nextstep.courses.infrastructure; -import nextstep.courses.domain.PaidSession; +import nextstep.courses.domain.session.PaidSession; import nextstep.payments.domain.Payment; import org.junit.jupiter.api.Test; diff --git a/src/test/java/nextstep/courses/infrastructure/SessionCoverImageTest.java b/src/test/java/nextstep/courses/infrastructure/SessionCoverImageTest.java index a09c3d541c..204c76df69 100644 --- a/src/test/java/nextstep/courses/infrastructure/SessionCoverImageTest.java +++ b/src/test/java/nextstep/courses/infrastructure/SessionCoverImageTest.java @@ -1,6 +1,6 @@ package nextstep.courses.infrastructure; -import nextstep.courses.domain.SessionCoverImage; +import nextstep.courses.domain.session.SessionCoverImage; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertFalse; diff --git a/src/test/java/nextstep/courses/infrastructure/SessionStatusTest.java b/src/test/java/nextstep/courses/infrastructure/SessionStatusTest.java index 873a0405f0..eb33f0f331 100644 --- a/src/test/java/nextstep/courses/infrastructure/SessionStatusTest.java +++ b/src/test/java/nextstep/courses/infrastructure/SessionStatusTest.java @@ -1,6 +1,6 @@ package nextstep.courses.infrastructure; -import nextstep.courses.domain.SessionStatus; +import nextstep.courses.domain.session.SessionStatus; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/nextstep/courses/infrastructure/SessionTest.java b/src/test/java/nextstep/courses/infrastructure/SessionTest.java index 72102a1a3d..310c6f008e 100644 --- a/src/test/java/nextstep/courses/infrastructure/SessionTest.java +++ b/src/test/java/nextstep/courses/infrastructure/SessionTest.java @@ -1,6 +1,6 @@ package nextstep.courses.infrastructure; -import nextstep.courses.domain.*; +import nextstep.courses.domain.session.*; import nextstep.payments.domain.Payment; import org.junit.jupiter.api.Test; From 786f774dd60a7dbd66d5f505a5912e936f21ac94 Mon Sep 17 00:00:00 2001 From: ming Date: Thu, 31 Oct 2024 19:28:18 +0900 Subject: [PATCH 22/23] =?UTF-8?q?feat:=202=EB=8B=A8=EA=B3=84=20-=20ImageEx?= =?UTF-8?q?tension(Enum),=20ImageSize,=20ImageDimensions=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + .../courses/domain/session/Session.java | 1 + .../domain/session/SessionCoverImage.java | 25 ---------------- .../session/coverImage/ImageDimensions.java | 26 ++++++++++++++++ .../session/coverImage/ImageExtension.java | 20 +++++++++++++ .../domain/session/coverImage/ImageSize.java | 18 +++++++++++ .../session/coverImage/SessionCoverImage.java | 23 ++++++++++++++ .../infrastructure/SessionCoverImageTest.java | 30 ++++++++++++------- .../courses/infrastructure/SessionTest.java | 23 ++++++++------ 9 files changed, 122 insertions(+), 45 deletions(-) delete mode 100644 src/main/java/nextstep/courses/domain/session/SessionCoverImage.java create mode 100644 src/main/java/nextstep/courses/domain/session/coverImage/ImageDimensions.java create mode 100644 src/main/java/nextstep/courses/domain/session/coverImage/ImageExtension.java create mode 100644 src/main/java/nextstep/courses/domain/session/coverImage/ImageSize.java create mode 100644 src/main/java/nextstep/courses/domain/session/coverImage/SessionCoverImage.java diff --git a/README.md b/README.md index 0080372732..63b872f70f 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ Answer - [x] 커버 이미지 정보 - gif, jpg, jpeg, png, svg만 허용 + - 이미지 크기 < 1 - width >= 300, height >= 200 / width * 2 = height * 3 - [x] 무료 강의 diff --git a/src/main/java/nextstep/courses/domain/session/Session.java b/src/main/java/nextstep/courses/domain/session/Session.java index 90638470b4..a5c4b37549 100644 --- a/src/main/java/nextstep/courses/domain/session/Session.java +++ b/src/main/java/nextstep/courses/domain/session/Session.java @@ -1,5 +1,6 @@ package nextstep.courses.domain.session; +import nextstep.courses.domain.session.coverImage.SessionCoverImage; import nextstep.payments.domain.Payment; import java.time.LocalDate; diff --git a/src/main/java/nextstep/courses/domain/session/SessionCoverImage.java b/src/main/java/nextstep/courses/domain/session/SessionCoverImage.java deleted file mode 100644 index e1349090ea..0000000000 --- a/src/main/java/nextstep/courses/domain/session/SessionCoverImage.java +++ /dev/null @@ -1,25 +0,0 @@ -package nextstep.courses.domain.session; - -import java.util.Arrays; - -public class SessionCoverImage { - private String extension; - private int width; - private int height; - - public SessionCoverImage(String extension, int width, int height){ - this.extension = extension; - this.width = width; - this.height = height; - } - - public boolean isValidCoverImage() { - if(!Arrays.asList("gif","jpg", "jpeg", "png", "svg").contains(extension)) { - return false; - } - if(width < 300 || height < 200 || width * 2 != height * 3) { - return false; - } - return true; - } -} diff --git a/src/main/java/nextstep/courses/domain/session/coverImage/ImageDimensions.java b/src/main/java/nextstep/courses/domain/session/coverImage/ImageDimensions.java new file mode 100644 index 0000000000..ca1d571dec --- /dev/null +++ b/src/main/java/nextstep/courses/domain/session/coverImage/ImageDimensions.java @@ -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() { + 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; + } +} diff --git a/src/main/java/nextstep/courses/domain/session/coverImage/ImageExtension.java b/src/main/java/nextstep/courses/domain/session/coverImage/ImageExtension.java new file mode 100644 index 0000000000..ea474460a8 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/session/coverImage/ImageExtension.java @@ -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)) { + throw new IllegalArgumentException("허용되지 않은 확장자 입니다."); + } + return true; + } + +} diff --git a/src/main/java/nextstep/courses/domain/session/coverImage/ImageSize.java b/src/main/java/nextstep/courses/domain/session/coverImage/ImageSize.java new file mode 100644 index 0000000000..1d5d858967 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/session/coverImage/ImageSize.java @@ -0,0 +1,18 @@ +package nextstep.courses.domain.session.coverImage; + +public class ImageSize { + private int size; + + 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; + } +} diff --git a/src/main/java/nextstep/courses/domain/session/coverImage/SessionCoverImage.java b/src/main/java/nextstep/courses/domain/session/coverImage/SessionCoverImage.java new file mode 100644 index 0000000000..4e740b80a5 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/session/coverImage/SessionCoverImage.java @@ -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(); + } +} diff --git a/src/test/java/nextstep/courses/infrastructure/SessionCoverImageTest.java b/src/test/java/nextstep/courses/infrastructure/SessionCoverImageTest.java index 204c76df69..9be9312943 100644 --- a/src/test/java/nextstep/courses/infrastructure/SessionCoverImageTest.java +++ b/src/test/java/nextstep/courses/infrastructure/SessionCoverImageTest.java @@ -1,30 +1,38 @@ package nextstep.courses.infrastructure; -import nextstep.courses.domain.session.SessionCoverImage; +import nextstep.courses.domain.session.coverImage.ImageExtension; +import nextstep.courses.domain.session.coverImage.SessionCoverImage; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; + public class SessionCoverImageTest { @Test - void 커버_이미지_확인__유효한_이미지(){ - SessionCoverImage image1 = new SessionCoverImage("gif", 300, 200); + void 커버_이미지_확인__유효한_이미지() { + SessionCoverImage image1 = new SessionCoverImage(1, ImageExtension.GIF, 300, 200); assertTrue(image1.isValidCoverImage()); } - + @Test - void 커버_이미지_확인__유효하지_않은_확장자(){ - SessionCoverImage image2 = new SessionCoverImage("bmp", 300, 200); + void 커버_이미지_확인__유효하지_않은_확장자() { + SessionCoverImage image2 = new SessionCoverImage(1, ImageExtension.BMP, 300, 200); assertFalse(image2.isValidCoverImage()); } - + @Test - void 커버_이미지_확인__유효하지_않은_이미지_사이즈(){ - SessionCoverImage image1 = new SessionCoverImage("gif", 200, 200); + void 커버_이미지_확인__유효하지_않은_이미지_사이즈() { + SessionCoverImage image1 = new SessionCoverImage(2, ImageExtension.GIF, 200, 200); assertFalse(image1.isValidCoverImage()); - SessionCoverImage image2 = new SessionCoverImage("gif", 300, 300); + } + + @Test + void 커버_이미지_확인__유효하지_않은_이미지_너비_높이() { + SessionCoverImage image2 = new SessionCoverImage(1, ImageExtension.GIF, 200, 200); assertFalse(image2.isValidCoverImage()); - SessionCoverImage image3 = new SessionCoverImage("gif", 300, 400); + SessionCoverImage image3 = new SessionCoverImage(1, ImageExtension.GIF, 300, 300); assertFalse(image3.isValidCoverImage()); + SessionCoverImage image4 = new SessionCoverImage(1, ImageExtension.GIF, 300, 400); + assertFalse(image4.isValidCoverImage()); } } diff --git a/src/test/java/nextstep/courses/infrastructure/SessionTest.java b/src/test/java/nextstep/courses/infrastructure/SessionTest.java index 310c6f008e..3f10aa9307 100644 --- a/src/test/java/nextstep/courses/infrastructure/SessionTest.java +++ b/src/test/java/nextstep/courses/infrastructure/SessionTest.java @@ -1,6 +1,11 @@ package nextstep.courses.infrastructure; -import nextstep.courses.domain.session.*; +import nextstep.courses.domain.session.FreeSession; +import nextstep.courses.domain.session.PaidSession; +import nextstep.courses.domain.session.Session; +import nextstep.courses.domain.session.SessionStatus; +import nextstep.courses.domain.session.coverImage.ImageExtension; +import nextstep.courses.domain.session.coverImage.SessionCoverImage; import nextstep.payments.domain.Payment; import org.junit.jupiter.api.Test; @@ -13,35 +18,35 @@ public class SessionTest { @Test void 커버_이미지_확인() { - session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, (payment) -> true); + session = new Session(new SessionCoverImage(1, ImageExtension.GIF, 300, 200), SessionStatus.RECRUITING, (payment) -> true); assertTrue(session.isValidCoverImage()); } @Test void 수강신청_가능여부_확인__인원초과_확인() { - session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, new PaidSession(3, 2, 20000)); + session = new Session(new SessionCoverImage(1, ImageExtension.GIF, 300, 200), SessionStatus.RECRUITING, new PaidSession(3, 2, 20000)); assertTrue(session.canEnroll(new Payment(20000L))); - session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, new PaidSession(2, 2, 20000)); + session = new Session(new SessionCoverImage(1, ImageExtension.GIF, 300, 200), SessionStatus.RECRUITING, new PaidSession(2, 2, 20000)); assertFalse(session.canEnroll(new Payment(20000L))); } @Test void 수강신청_가능여부_확인__강의_수강료_확인() { - session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, new PaidSession(3, 2, 20000)); + session = new Session(new SessionCoverImage(1, ImageExtension.GIF, 300, 200), SessionStatus.RECRUITING, new PaidSession(3, 2, 20000)); assertTrue(session.canEnroll(new Payment(20000L))); - session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, new PaidSession(3, 2, 20000)); + session = new Session(new SessionCoverImage(1, ImageExtension.GIF, 300, 200), SessionStatus.RECRUITING, new PaidSession(3, 2, 20000)); assertFalse(session.canEnroll(new Payment(15000L))); } @Test void 수강신청_가능여부_확인__강의_상태_모집중() { - session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.RECRUITING, (payment) -> true); + session = new Session(new SessionCoverImage(1, ImageExtension.GIF, 300, 200), SessionStatus.RECRUITING, (payment) -> true); assertTrue(session.canEnroll(new Payment(20000L))); - session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.CLOSED, new FreeSession()); + session = new Session(new SessionCoverImage(1, ImageExtension.GIF, 300, 200), SessionStatus.CLOSED, new FreeSession()); assertFalse(session.canEnroll(new Payment(0L))); - session = new Session(new SessionCoverImage("gif", 300, 200), SessionStatus.CLOSED, new PaidSession(3, 2, 20000)); + session = new Session(new SessionCoverImage(1, ImageExtension.GIF, 300, 200), SessionStatus.CLOSED, new PaidSession(3, 2, 20000)); assertFalse(session.canEnroll(new Payment(20000L))); } From 950b4a83c15bcf4bc54ff3d98496e9dca140bb2e Mon Sep 17 00:00:00 2001 From: ming Date: Sun, 10 Nov 2024 17:17:48 +0900 Subject: [PATCH 23/23] =?UTF-8?q?refeactor:=202=EB=8B=A8=EA=B3=84=20?= =?UTF-8?q?=ED=94=BC=EB=93=9C=EB=B0=B1=20=EB=B0=98=EC=98=81=20-=20?= =?UTF-8?q?=EC=9C=A0=ED=9A=A8=ED=95=9C=20=ED=99=95=EC=9E=A5=EC=9E=90=20?= =?UTF-8?q?=EC=83=81=EC=88=98=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../courses/domain/session/coverImage/ImageExtension.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/nextstep/courses/domain/session/coverImage/ImageExtension.java b/src/main/java/nextstep/courses/domain/session/coverImage/ImageExtension.java index ea474460a8..c3b5551541 100644 --- a/src/main/java/nextstep/courses/domain/session/coverImage/ImageExtension.java +++ b/src/main/java/nextstep/courses/domain/session/coverImage/ImageExtension.java @@ -1,6 +1,7 @@ package nextstep.courses.domain.session.coverImage; import java.util.Arrays; +import java.util.List; public enum ImageExtension { GIF, @@ -10,8 +11,10 @@ public enum ImageExtension { SVG, BMP; + private static final List VALID_EXTENSION = Arrays.asList(GIF, JPG, JPEG, PNG, SVG); + public static boolean validExtension(ImageExtension extension) { - if (!Arrays.asList(GIF, JPG, JPEG, PNG, SVG).contains(extension)) { + if (!VALID_EXTENSION.contains(extension)) { throw new IllegalArgumentException("허용되지 않은 확장자 입니다."); } return true;