-
Notifications
You must be signed in to change notification settings - Fork 300
๐ 1๋จ๊ณ - ๋ ๊ฑฐ์ ์ฝ๋ ๋ฆฌํฉํฐ๋ง #790
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
base: chanani
Are you sure you want to change the base?
Changes from 7 commits
c4960b6
a117751
3cdb2ed
9c9d031
625a895
188c9d7
8312ece
f1b3547
54e1f6d
c4db9bd
400b772
73effd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # ๐ 1๋จ๊ณ - ๋ ๊ฑฐ์ ์ฝ๋ ๋ฆฌํฉํฐ๋ง | ||
| *** | ||
|
|
||
| ## ์ฝ๋ ๋ฆฌ๋ทฐ | ||
| > PR ๋งํฌ : | ||
| ## ๋์ ํ์ต ๋ชฉํ | ||
|
|
||
| ### 1. TDD ์ฌ์ดํด์ ์์ํ๋ฉฐ ๊ธฐ๋ฅ์ ๊ตฌํํ๋ค. | ||
| - `์คํจ โ ์ฑ๊ณต โ ๋ฆฌํฉํฐ๋ง` ๊ณผ์ ์ผ๋ก ์์ ํ๋ค. | ||
| - ์ต๊ด์ฒ๋ผ ์ด ๊ณผ์ ์ ์ง๋์น๋ฉด, ๋ค์ ๋์์ ์ฌ์ดํด์ ๋ฐ๋ณตํ๋ค. | ||
| - TDD ์ฌ์ดํด ์ต๊ด์ ๋ง๋ค์. | ||
|
|
||
| ### 2. ๋๋ฉ์ธ์ ํนํ๋ ์ด๋ฆ์ ์ง๋๋ค. | ||
| - AI์๊ฒ ์ถ์ฒ ๋ฐ๋ ์ต๊ด์ ๋ง๋ค์. | ||
|
|
||
| ### 3. ๋ฐ๋ณต๋ ํผ๋๋ฐฑ์ ํผํ์. | ||
| - ๊ฐ์ ํผ๋๋ฐฑ์ ๋ฐ๋ณตํ์ง ์๋๋ก, ์ฒดํฌ๋ฆฌ์คํธ๋ฅผ ๋ง๋ค์ด ์ ๊ฒํ์. | ||
|
|
||
| ## ์ง๋ฌธ ์ญ์ ํ๊ธฐ ์๊ตฌ์ฌํญ | ||
|
|
||
| - [x] ์ง๋ฌธ ๋ฐ์ดํฐ๋ฅผ ์์ ํ ์ญ์ ํ๋ ๊ฒ์ด ์๋๋ผ ๋ฐ์ดํฐ์ ์ํ๋ฅผ ์ญ์ ์ํ(deleted - boolean type)๋ก ๋ณ๊ฒฝํ๋ค. | ||
| - [x] ๋ก๊ทธ์ธ ์ฌ์ฉ์์ ์ง๋ฌธํ ์ฌ๋์ด ๊ฐ์ ๊ฒฝ์ฐ ์ญ์ ๊ฐ๋ฅํ๋ค. | ||
| - [x] ๋ต๋ณ์ด ์๋ ๊ฒฝ์ฐ ์ญ์ ๊ฐ ๊ฐ๋ฅํ๋ค. | ||
| - [x] ์ง๋ฌธ์์ ๋ต๋ณ ๊ธ์ ๋ชจ๋ ๋ต๋ณ์๊ฐ ๊ฐ์ ๊ฒฝ์ฐ ์ญ์ ๊ฐ ๊ฐ๋ฅํ๋ค. | ||
| - [x] ์ง๋ฌธ์ ์ญ์ ํ ๋ ๋ต๋ณ ๋ํ ์ญ์ ํด์ผ ํ๋ฉฐ, ๋ต๋ณ์ ์ญ์ ๋ํ ์ญ์ ์ํ(deleted)๋ฅผ ๋ณ๊ฒฝํ๋ค. | ||
| - [x] ์ง๋ฌธ์์ ๋ต๋ณ์๊ฐ ๋ค๋ฅธ ๊ฒฝ์ฐ ๋ต๋ณ์ ์ญ์ ํ ์ ์๋ค. | ||
| - [x] ์ง๋ฌธ๊ณผ ๋ต๋ณ ์ญ์ ์ด๋ ฅ์ ๋ํ ์ ๋ณด๋ฅผ DeleteHistory๋ฅผ ํ์ฉํด ๋จ๊ธด๋ค. | ||
|
|
||
| ## ๋ฆฌํฉํฐ๋ง ์๊ตฌ์ฌํญ | ||
|
|
||
| - [x] nextstep.qna.service.QnaService์ deleteQuestion()๋ ์์ ์ง๋ฌธ ์ญ์ ๊ธฐ๋ฅ์ ๊ตฌํํ ์ฝ๋์ด๋ค. | ||
| ์ด ๋ฉ์๋๋ ๋จ์ ํ ์คํธํ๊ธฐ ์ด๋ ค์ด ์ฝ๋์ ๋จ์ ํ ์คํธ ๊ฐ๋ฅํ ์ฝ๋๊ฐ ์์ฌ ์๋ค. | ||
| - [x] QnaService์ deleteQuestion() ๋ฉ์๋์ ๋จ์ ํ ์คํธ ๊ฐ๋ฅํ ์ฝ๋(ํต์ฌ ๋น์ง๋์ค ๋ก์ง)๋ฅผ ๋๋ฉ์ธ ๋ชจ๋ธ ๊ฐ์ฒด์ ๊ตฌํํ๋ค. | ||
| - [x] QnaService์ ๋น์ง๋์ค ๋ก์ง์ ๋๋ฉ์ธ ๋ชจ๋ธ๋ก ์ด๋ํ๋ ๋ฆฌํฉํฐ๋ง์ ์งํํ ๋ TDD๋ก ๊ตฌํํ๋ค. | ||
| - [x] QnaService์ deleteQuestion() ๋ฉ์๋์ ๋ํ ๋จ์ ํ ์คํธ๋ src/test/java ํด๋ nextstep.qna.service.QnaServiceTest์ด๋ค. | ||
| ๋๋ฉ์ธ ๋ชจ๋ธ๋ก ๋ก์ง์ ์ด๋ํ ํ์๋ QnaServiceTest์ ๋ชจ๋ ํ ์คํธ๋ ํต๊ณผํด์ผ ํ๋ค. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # โ๏ธ PR ์ ํ์ธํด์ผ๋ ๋ชฉ๋ก | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐ |
||
| *** | ||
|
|
||
| - ๊ฐ์ฒด์งํฅ ์ํ์ฒด์กฐ ์์น์ ์ค์ํ์๋๊ฐ ? | ||
| - TDD ์ฌ์ดํด๋ก ๊ตฌํํ์๋๊ฐ ? | ||
| - TDD ์ฌ์ดํด ๋จ์๋ก ์ปค๋ฐํ์๋๊ฐ ? | ||
| - ๊ฐ์ฒด์๊ฒ ์ํ๋ฅผ ๋ ธ์ถ์ํค์ง ์๊ณ ์ฑ ์์ ๋งก๊ฒผ๋๊ฐ ? | ||
| - ํ ์ฝ์ผ๋ ๊ฐ์ฒด์ ์ฑ ์๊ณผ ๊ฒฐ๊ณผ๋ง ๊ฒ์ฆํ๋๊ฐ ? | ||
| - ๋ถ๋ณ์ฑ์ ์ต๋ํ ์ ์งํ๋๊ฐ ? | ||
| - ๋๋ฉ์ธ ์ฉ์ด๋ก ๋ค์ด๋ฐ ํ๋๊ฐ ? | ||
| - ํ๋ ฅ ๊ตฌ์กฐ๊ฐ ์์ฐ์ค๋ฝ๊ฒ ์ฝํ๋๊ฐ ? | ||
| - ๊ฐ์ ํผ๋๋ฐฑ์ ๋ฐ๋ณตํ์ง๋ ์์๋๊ฐ ? | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||
| package nextstep.qna.domain; | ||||||||||
|
|
||||||||||
| import nextstep.qna.CannotDeleteException; | ||||||||||
| import nextstep.qna.NotFoundException; | ||||||||||
| import nextstep.qna.UnAuthorizedException; | ||||||||||
| import nextstep.users.domain.NsUser; | ||||||||||
|
|
@@ -30,11 +31,11 @@ public Answer(NsUser writer, Question question, String contents) { | |||||||||
|
|
||||||||||
| public Answer(Long id, NsUser writer, Question question, String contents) { | ||||||||||
| this.id = id; | ||||||||||
| if(writer == null) { | ||||||||||
| if (writer == null) { | ||||||||||
| throw new UnAuthorizedException(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if(question == null) { | ||||||||||
| if (question == null) { | ||||||||||
| throw new NotFoundException(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -52,6 +53,10 @@ public Answer setDeleted(boolean deleted) { | |||||||||
| return this; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public void updateDeleted(){ | ||||||||||
| this.deleted = true; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public boolean isDeleted() { | ||||||||||
| return deleted; | ||||||||||
| } | ||||||||||
|
|
@@ -72,6 +77,12 @@ public void toQuestion(Question question) { | |||||||||
| this.question = question; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public void validateAnswerOwner(NsUser loginUser) throws CannotDeleteException { | ||||||||||
| if (!this.isOwner(loginUser)) { | ||||||||||
| throw new CannotDeleteException("๋ค๋ฅธ ์ฌ๋์ด ์ด ๋ต๋ณ์ด ์์ด ์ญ์ ํ ์ ์์ต๋๋ค."); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ํ์ฌ๋ valid์ updateDeleted๊ฐ ๋ถ๋ฆฌ๋์ด ๊ตฌํ๋์ด ์์.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ด ํผ๋๋ฐฑ ๋ฐ์ํ๋์ง ํ์ธ ํ์ |
||||||||||
| @Override | ||||||||||
| public String toString() { | ||||||||||
| return "Answer [id=" + getId() + ", writer=" + writer + ", contents=" + contents + "]"; | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,34 @@ | ||||||||
| package nextstep.qna.domain; | ||||||||
|
|
||||||||
| import nextstep.qna.CannotDeleteException; | ||||||||
| import nextstep.users.domain.NsUser; | ||||||||
|
|
||||||||
| import java.time.LocalDateTime; | ||||||||
| import java.util.ArrayList; | ||||||||
| import java.util.List; | ||||||||
|
|
||||||||
| public class Answers { | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ผ๊ธ ์ฝ๋ ์ ์ ์ฉ ๐ |
||||||||
|
|
||||||||
| private List<Answer> answers = new ArrayList<>(); | ||||||||
|
|
||||||||
| public void add(Answer answer) { | ||||||||
| this.answers.add(answer); | ||||||||
| } | ||||||||
|
|
||||||||
| public List<Answer> getAnswers() { | ||||||||
| return answers; | ||||||||
| } | ||||||||
|
|
||||||||
| public void validateAnswerOwner(NsUser loginUser) throws CannotDeleteException { | ||||||||
| for (Answer answer : this.answers) { | ||||||||
| answer.validateAnswerOwner(loginUser); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| public void addDeleteAnswerHistory(List<DeleteHistory> deleteHistories) { | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
๊ฐ์ธ์ ์ผ๋ก List ์ฝ๋ ์ ์ ์ธ์๋ก ์ ๋ฌํด ์ ์ฅํ๋ ๊ฒ๋ณด๋ค ์์ ๊ฐ์ด ํด๋น ๋ฉ์๋์์ ์ง์ ์์ฑํด ๋ฐํํ๋ ๊ฒ์ด ๋ค๋ฅธ ๊ฐ์ฒด์์ ์์กด ๊ด๊ณ๊ฐ ๋ฐ์ํ์ง ์๊ธฐ ๋๋ฌธ์ ์ ํธํ๋ ๋ฐฉ๋ฒ์ |
||||||||
| for (Answer answer : this.answers) { | ||||||||
| answer.updateDeleted(); | ||||||||
| deleteHistories.add(new DeleteHistory(ContentType.ANSWER, answer.getId(), answer.getWriter(), LocalDateTime.now())); | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||
| package nextstep.qna.domain; | ||||||||||
|
|
||||||||||
| import nextstep.qna.CannotDeleteException; | ||||||||||
| import nextstep.users.domain.NsUser; | ||||||||||
|
|
||||||||||
| import java.time.LocalDateTime; | ||||||||||
|
|
@@ -15,7 +16,7 @@ public class Question { | |||||||||
|
|
||||||||||
| private NsUser writer; | ||||||||||
|
|
||||||||||
| private List<Answer> answers = new ArrayList<>(); | ||||||||||
| private Answers answers = new Answers(); | ||||||||||
|
|
||||||||||
| private boolean deleted = false; | ||||||||||
|
|
||||||||||
|
|
@@ -65,7 +66,7 @@ public NsUser getWriter() { | |||||||||
|
|
||||||||||
| public void addAnswer(Answer answer) { | ||||||||||
| answer.toQuestion(this); | ||||||||||
| answers.add(answer); | ||||||||||
| this.answers.add(answer); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public boolean isOwner(NsUser loginUser) { | ||||||||||
|
|
@@ -82,11 +83,42 @@ public boolean isDeleted() { | |||||||||
| } | ||||||||||
|
|
||||||||||
| public List<Answer> getAnswers() { | ||||||||||
| return answers; | ||||||||||
| return answers.getAnswers(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public void validateDeletable(NsUser loginUser) throws CannotDeleteException { | ||||||||||
| validateOwner(loginUser); | ||||||||||
| answers.validateAnswerOwner(loginUser); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private void validateOwner(NsUser loginUser) throws CannotDeleteException { | ||||||||||
| if (!this.isOwner(loginUser)) { | ||||||||||
| throw new CannotDeleteException("์ง๋ฌธ์ ์ญ์ ํ ๊ถํ์ด ์์ต๋๋ค."); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public List<DeleteHistory> delete(long questionId) { | ||||||||||
|
||||||||||
| public List<DeleteHistory> delete(long questionId) { | |
| public List<DeleteHistory> delete() { |
questionid๋ Question์ด ๊ฐ์ง๊ณ ์์.
๊ตณ์ด ํ์์์ง ์์๊น?
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| public List<DeleteHistory> delete(long questionId) { | |
| public void delete(NsUser loginUser) { |
Answer ํผ๋๋ฐฑ๊ณผ ๊ฐ์ด ํ์ฌ ๋๋ก ๋ถ๋ฆฌ๋์ด ์๋ ๊ตฌํ๊ณผ ์์ ๊ฐ์ด ์ญ์ ๊ถํ ์ฒดํฌ์ฌ๋ถ์ deleted ์ํ ๋ณ๊ฒฝ ๋ก์ง์ ํจ๊ป ๊ตฌํํ๋ ์ ์ ๊ทผ ๋ฐฉ์ ์ค ์ด๋ ์ ๊ทผ ๋ฐฉ์์ด ์ข์์ง ๊ณ ๋ฏผํด ๋ณด๋ฉด ์ด๋จ๊น?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํ์ฌ๋ delete()์์ ์ํ ๋ณ๊ฒฝ๊ณผ List ์์ฑ ํ ๋ฐํํ๋ ํ์ฌ ๊ตฌํ๊ณผ delete()์ toDeleteHistories()์ ๊ฐ์ด ์ํ ๋ณ๊ฒฝ๊ณผ List ๋ฐํํ๋ ๋ฉ์๋ ๋ ๊ฐ๋ก ๋ถ๋ฆฌํ๋ ๊ฒ ์ค ์ด๋ ์ ๊ทผ ๋ฐฉ์์ด ์ข์๊น?
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,26 @@ | ||
| package nextstep.qna.domain; | ||
|
|
||
| import nextstep.qna.CannotDeleteException; | ||
| import nextstep.users.domain.NsUserTest; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.*; | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| public class AnswerTest { | ||
| public static final Answer A1 = new Answer(NsUserTest.JAVAJIGI, QuestionTest.Q1, "Answers Contents1"); | ||
| public static final Answer A2 = new Answer(NsUserTest.SANJIGI, QuestionTest.Q1, "Answers Contents2"); | ||
|
|
||
| @Test | ||
| void ๋ค๋ฅธ_์ฌ์ฉ์๊ฐ_์์ฑํ_๋ต๋ณ์ด_์กด์ฌํ๋ฉด_์๋ฌ๋ฐ์(){ | ||
| assertThrows(CannotDeleteException.class, () -> { | ||
| A1.validateAnswerOwner(NsUserTest.SANJIGI); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| void ๋ต๋ณ์ญ์ (){ | ||
| A1.updateDeleted(); | ||
| assertThat(A1.isDeleted()).isTrue(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,32 @@ | ||
| package nextstep.qna.domain; | ||
|
|
||
| import nextstep.qna.CannotDeleteException; | ||
| import nextstep.users.domain.NsUserTest; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.assertj.core.api.Assertions.*; | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| public class QuestionTest { | ||
| public static final Question Q1 = new Question(NsUserTest.JAVAJIGI, "title1", "contents1"); | ||
| public static final Question Q2 = new Question(NsUserTest.SANJIGI, "title2", "contents2"); | ||
|
|
||
| @Test | ||
| void ๊ธ์ด์ด๊ฐ_๋ก๊ทธ์ธํ_์ ์ ์_๊ฐ์ง์์ผ๋ฉด_์๋ฌ๋ฐ์(){ | ||
| assertThrows(CannotDeleteException.class, () -> { | ||
| Q1.validateDeletable(NsUserTest.SANJIGI); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| void ์ง๋ฌธ_๋ต๊ธ_์ญ์ _๋ชฉ๋ก_์กฐํ(){ | ||
| List<DeleteHistory> deleteHistories = Q1.delete(1L); | ||
| assertThat(deleteHistories).hasSize(1); | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๐