From c4960b6238ab6694e9db72b8ab459e641fd31fbe Mon Sep 17 00:00:00 2001 From: CHANHAN <130114269+chanani@users.noreply.github.com> Date: Tue, 25 Nov 2025 14:46:35 +0900 Subject: [PATCH 01/16] =?UTF-8?q?docs=20:=20=EA=B8=B0=EB=8A=A5=20=EC=9A=94?= =?UTF-8?q?=EA=B5=AC=EC=82=AC=ED=95=AD=20=EB=AC=B8=EC=84=9C=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 --- docs/01-refactoring.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 docs/01-refactoring.md diff --git a/docs/01-refactoring.md b/docs/01-refactoring.md new file mode 100644 index 0000000000..35af91ff5d --- /dev/null +++ b/docs/01-refactoring.md @@ -0,0 +1,21 @@ +# ๐Ÿš€ 1๋‹จ๊ณ„ - ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ ๋ฆฌํŒฉํ„ฐ๋ง +*** + +### ์งˆ๋ฌธ ์‚ญ์ œํ•˜๊ธฐ ์š”๊ตฌ์‚ฌํ•ญ + +- [ ] ์งˆ๋ฌธ ๋ฐ์ดํ„ฐ๋ฅผ ์™„์ „ํžˆ ์‚ญ์ œํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ๋ฐ์ดํ„ฐ์˜ ์ƒํƒœ๋ฅผ ์‚ญ์ œ ์ƒํƒœ(deleted - boolean type)๋กœ ๋ณ€๊ฒฝํ•œ๋‹ค. +- [ ] ๋กœ๊ทธ์ธ ์‚ฌ์šฉ์ž์™€ ์งˆ๋ฌธํ•œ ์‚ฌ๋žŒ์ด ๊ฐ™์€ ๊ฒฝ์šฐ ์‚ญ์ œ ๊ฐ€๋Šฅํ•˜๋‹ค. +- [ ] ๋‹ต๋ณ€์ด ์—†๋Š” ๊ฒฝ์šฐ ์‚ญ์ œ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค. +- [ ] ์งˆ๋ฌธ์ž์™€ ๋‹ต๋ณ€ ๊ธ€์˜ ๋ชจ๋“  ๋‹ต๋ณ€์ž๊ฐ€ ๊ฐ™์€ ๊ฒฝ์šฐ ์‚ญ์ œ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค. +- [ ] ์งˆ๋ฌธ์„ ์‚ญ์ œํ•  ๋•Œ ๋‹ต๋ณ€ ๋˜ํ•œ ์‚ญ์ œํ•ด์•ผ ํ•˜๋ฉฐ, ๋‹ต๋ณ€์˜ ์‚ญ์ œ ๋˜ํ•œ ์‚ญ์ œ ์ƒํƒœ(deleted)๋ฅผ ๋ณ€๊ฒฝํ•œ๋‹ค. +- [ ] ์งˆ๋ฌธ์ž์™€ ๋‹ต๋ณ€์ž๊ฐ€ ๋‹ค๋ฅธ ๊ฒฝ์šฐ ๋‹ต๋ณ€์„ ์‚ญ์ œํ•  ์ˆ˜ ์—†๋‹ค. +- [ ] ์งˆ๋ฌธ๊ณผ ๋‹ต๋ณ€ ์‚ญ์ œ ์ด๋ ฅ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ DeleteHistory๋ฅผ ํ™œ์šฉํ•ด ๋‚จ๊ธด๋‹ค. + +### ๋ฆฌํŒฉํ„ฐ๋ง ์š”๊ตฌ์‚ฌํ•ญ + +- [ ] nextstep.qna.service.QnaService์˜ deleteQuestion()๋Š” ์•ž์˜ ์งˆ๋ฌธ ์‚ญ์ œ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•œ ์ฝ”๋“œ์ด๋‹ค. + ์ด ๋ฉ”์†Œ๋“œ๋Š” ๋‹จ์œ„ ํ…Œ์ŠคํŠธํ•˜๊ธฐ ์–ด๋ ค์šด ์ฝ”๋“œ์™€ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ๊ฐ€๋Šฅํ•œ ์ฝ”๋“œ๊ฐ€ ์„ž์—ฌ ์žˆ๋‹ค. +- [ ] QnaService์˜ deleteQuestion() ๋ฉ”์„œ๋“œ์— ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ๊ฐ€๋Šฅํ•œ ์ฝ”๋“œ(ํ•ต์‹ฌ ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง)๋ฅผ ๋„๋ฉ”์ธ ๋ชจ๋ธ ๊ฐ์ฒด์— ๊ตฌํ˜„ํ•œ๋‹ค. +- [ ] QnaService์˜ ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง์„ ๋„๋ฉ”์ธ ๋ชจ๋ธ๋กœ ์ด๋™ํ•˜๋Š” ๋ฆฌํŒฉํ„ฐ๋ง์„ ์ง„ํ–‰ํ•  ๋•Œ TDD๋กœ ๊ตฌํ˜„ํ•œ๋‹ค. +- [ ] QnaService์˜ deleteQuestion() ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•œ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋Š” src/test/java ํด๋” nextstep.qna.service.QnaServiceTest์ด๋‹ค. + ๋„๋ฉ”์ธ ๋ชจ๋ธ๋กœ ๋กœ์ง์„ ์ด๋™ํ•œ ํ›„์—๋„ QnaServiceTest์˜ ๋ชจ๋“  ํ…Œ์ŠคํŠธ๋Š” ํ†ต๊ณผํ•ด์•ผ ํ•œ๋‹ค. \ No newline at end of file From a117751b198c49f3a79e287d21ff031a8c498ded Mon Sep 17 00:00:00 2001 From: CHANHAN <130114269+chanani@users.noreply.github.com> Date: Tue, 25 Nov 2025 15:09:07 +0900 Subject: [PATCH 02/16] =?UTF-8?q?docs=20:=20=EB=82=98=EC=9D=98=20=ED=95=99?= =?UTF-8?q?=EC=8A=B5=20=EB=AA=A9=ED=91=9C,=20PR=EC=A0=84=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=ED=95=B4=EC=95=BC=ED=95=A0=20=EB=AA=A9=EB=A1=9D=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1(=ED=98=B8=EC=84=B1=EB=8B=98=EC=9D=B4=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=ED=95=9C=20=EB=82=B4=EC=9A=A9=EC=97=90=20?= =?UTF-8?q?=EA=B0=90=EB=AA=85=20=EB=B0=9B=EC=95=84=20=EC=A0=80=EB=8F=84=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=ED=95=98=EB=A0=A4=EA=B3=A0=ED=95=A9=EB=8B=88?= =?UTF-8?q?=EB=8B=A4.)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/01-refactoring.md | 20 ++++++++++++++++++-- docs/check-list.md | 12 ++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 docs/check-list.md diff --git a/docs/01-refactoring.md b/docs/01-refactoring.md index 35af91ff5d..13ff04b7c6 100644 --- a/docs/01-refactoring.md +++ b/docs/01-refactoring.md @@ -1,7 +1,23 @@ # ๐Ÿš€ 1๋‹จ๊ณ„ - ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ ๋ฆฌํŒฉํ„ฐ๋ง *** -### ์งˆ๋ฌธ ์‚ญ์ œํ•˜๊ธฐ ์š”๊ตฌ์‚ฌํ•ญ +## ์ฝ”๋“œ ๋ฆฌ๋ทฐ +> PR ๋งํฌ : + +## ๋‚˜์˜ ํ•™์Šต ๋ชฉํ‘œ + +### 1. TDD ์‚ฌ์ดํด์„ ์˜์‹ํ•˜๋ฉฐ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•œ๋‹ค. +- `์‹คํŒจ โ†’ ์„ฑ๊ณต โ†’ ๋ฆฌํŒฉํ„ฐ๋ง` ๊ณผ์ •์œผ๋กœ ์ž‘์—…ํ•œ๋‹ค. +- ์Šต๊ด€์ฒ˜๋Ÿผ ์ด ๊ณผ์ •์„ ์ง€๋‚˜์น˜๋ฉด, ๋‹ค์‹œ ๋Œ์•„์™€ ์‚ฌ์ดํด์„ ๋ฐ˜๋ณตํ•œ๋‹ค. +- TDD ์‚ฌ์ดํด ์Šต๊ด€์„ ๋งŒ๋“ค์ž. + +### 2. ๋„๋ฉ”์ธ์— ํŠนํ™”๋œ ์ด๋ฆ„์„ ์ง“๋Š”๋‹ค. +- AI์—๊ฒŒ ์ถ”์ฒœ ๋ฐ›๋Š” ์Šต๊ด€์„ ๋งŒ๋“ค์ž. + +### 3. ๋ฐ˜๋ณต๋œ ํ”ผ๋“œ๋ฐฑ์€ ํ”ผํ•˜์ž. +- ๊ฐ™์€ ํ”ผ๋“œ๋ฐฑ์„ ๋ฐ˜๋ณตํ•˜์ง€ ์•Š๋„๋ก, ์ฒดํฌ๋ฆฌ์ŠคํŠธ๋ฅผ ๋งŒ๋“ค์–ด ์ ๊ฒ€ํ•˜์ž. + +## ์งˆ๋ฌธ ์‚ญ์ œํ•˜๊ธฐ ์š”๊ตฌ์‚ฌํ•ญ - [ ] ์งˆ๋ฌธ ๋ฐ์ดํ„ฐ๋ฅผ ์™„์ „ํžˆ ์‚ญ์ œํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ๋ฐ์ดํ„ฐ์˜ ์ƒํƒœ๋ฅผ ์‚ญ์ œ ์ƒํƒœ(deleted - boolean type)๋กœ ๋ณ€๊ฒฝํ•œ๋‹ค. - [ ] ๋กœ๊ทธ์ธ ์‚ฌ์šฉ์ž์™€ ์งˆ๋ฌธํ•œ ์‚ฌ๋žŒ์ด ๊ฐ™์€ ๊ฒฝ์šฐ ์‚ญ์ œ ๊ฐ€๋Šฅํ•˜๋‹ค. @@ -11,7 +27,7 @@ - [ ] ์งˆ๋ฌธ์ž์™€ ๋‹ต๋ณ€์ž๊ฐ€ ๋‹ค๋ฅธ ๊ฒฝ์šฐ ๋‹ต๋ณ€์„ ์‚ญ์ œํ•  ์ˆ˜ ์—†๋‹ค. - [ ] ์งˆ๋ฌธ๊ณผ ๋‹ต๋ณ€ ์‚ญ์ œ ์ด๋ ฅ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ DeleteHistory๋ฅผ ํ™œ์šฉํ•ด ๋‚จ๊ธด๋‹ค. -### ๋ฆฌํŒฉํ„ฐ๋ง ์š”๊ตฌ์‚ฌํ•ญ +## ๋ฆฌํŒฉํ„ฐ๋ง ์š”๊ตฌ์‚ฌํ•ญ - [ ] nextstep.qna.service.QnaService์˜ deleteQuestion()๋Š” ์•ž์˜ ์งˆ๋ฌธ ์‚ญ์ œ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•œ ์ฝ”๋“œ์ด๋‹ค. ์ด ๋ฉ”์†Œ๋“œ๋Š” ๋‹จ์œ„ ํ…Œ์ŠคํŠธํ•˜๊ธฐ ์–ด๋ ค์šด ์ฝ”๋“œ์™€ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ๊ฐ€๋Šฅํ•œ ์ฝ”๋“œ๊ฐ€ ์„ž์—ฌ ์žˆ๋‹ค. diff --git a/docs/check-list.md b/docs/check-list.md new file mode 100644 index 0000000000..c54ca0d887 --- /dev/null +++ b/docs/check-list.md @@ -0,0 +1,12 @@ +# โœ”๏ธ PR ์ „ ํ™•์ธํ•ด์•ผ๋  ๋ชฉ๋ก +*** + +- ๊ฐ์ฒด์ง€ํ–ฅ ์ƒํ™œ์ฒด์กฐ ์›์น™์„ ์ค€์ˆ˜ํ•˜์˜€๋Š”๊ฐ€ ? +- TDD ์‚ฌ์ดํด๋กœ ๊ตฌํ˜„ํ•˜์˜€๋Š”๊ฐ€ ? +- TDD ์‚ฌ์ดํด ๋‹จ์œ„๋กœ ์ปค๋ฐ‹ํ•˜์˜€๋Š”๊ฐ€ ? +- ๊ฐ์ฒด์—๊ฒŒ ์ƒํƒœ๋ฅผ ๋…ธ์ถœ์‹œํ‚ค์ง€ ์•Š๊ณ  ์ฑ…์ž„์„ ๋งก๊ฒผ๋Š”๊ฐ€ ? +- ํ…Œ์Šฝ์œผ๋Š” ๊ฐ์ฒด์˜ ์ฑ…์ž„๊ณผ ๊ฒฐ๊ณผ๋งŒ ๊ฒ€์ฆํ–ˆ๋Š”๊ฐ€ ? +- ๋ถˆ๋ณ€์„ฑ์„ ์ตœ๋Œ€ํ•œ ์œ ์ง€ํ–ˆ๋Š”๊ฐ€ ? +- ๋„๋ฉ”์ธ ์šฉ์–ด๋กœ ๋„ค์ด๋ฐ ํ–ˆ๋Š”๊ฐ€ ? +- ํ˜‘๋ ฅ ๊ตฌ์กฐ๊ฐ€ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์ฝํžˆ๋Š”๊ฐ€ ? +- ๊ฐ™์€ ํ”ผ๋“œ๋ฐฑ์„ ๋ฐ˜๋ณตํ•˜์ง€๋Š” ์•Š์•˜๋Š”๊ฐ€ ? \ No newline at end of file From 3cdb2ed6525d56a8ceb65695cdfc027169fec86e Mon Sep 17 00:00:00 2001 From: CHANHAN <130114269+chanani@users.noreply.github.com> Date: Tue, 25 Nov 2025 15:12:52 +0900 Subject: [PATCH 03/16] =?UTF-8?q?refactor=20:=20Question=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=EC=97=90=20=EC=A7=88=EB=AC=B8=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EA=B6=8C=ED=95=9C=20=EC=B2=B4=ED=81=AC=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=83=9D=EC=84=B1=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1,=20Answer?= =?UTF-8?q?=20=EA=B0=9D=EC=B2=B4=EC=97=90=20=EC=82=AD=EC=A0=9C=20=EA=B6=8C?= =?UTF-8?q?=ED=95=9C=20=EC=B2=B4=ED=81=AC=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EB=B0=8F=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 --- src/main/java/nextstep/qna/domain/Answer.java | 11 +++++++++-- src/main/java/nextstep/qna/domain/Question.java | 7 +++++++ src/main/java/nextstep/qna/service/QnAService.java | 9 +++------ src/test/java/nextstep/qna/domain/AnswerTest.java | 10 ++++++++++ src/test/java/nextstep/qna/domain/QuestionTest.java | 13 +++++++++++++ 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/main/java/nextstep/qna/domain/Answer.java b/src/main/java/nextstep/qna/domain/Answer.java index cf681811e7..8899ad68ca 100644 --- a/src/main/java/nextstep/qna/domain/Answer.java +++ b/src/main/java/nextstep/qna/domain/Answer.java @@ -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(); } @@ -72,6 +73,12 @@ public void toQuestion(Question question) { this.question = question; } + public void validateAnswerOwner(NsUser loginUser) throws CannotDeleteException { + if (!this.isOwner(loginUser)) { + throw new CannotDeleteException("๋‹ค๋ฅธ ์‚ฌ๋žŒ์ด ์“ด ๋‹ต๋ณ€์ด ์žˆ์–ด ์‚ญ์ œํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + } + } + @Override public String toString() { return "Answer [id=" + getId() + ", writer=" + writer + ", contents=" + contents + "]"; diff --git a/src/main/java/nextstep/qna/domain/Question.java b/src/main/java/nextstep/qna/domain/Question.java index b623c52c76..773fb55e84 100644 --- a/src/main/java/nextstep/qna/domain/Question.java +++ b/src/main/java/nextstep/qna/domain/Question.java @@ -1,5 +1,6 @@ package nextstep.qna.domain; +import nextstep.qna.CannotDeleteException; import nextstep.users.domain.NsUser; import java.time.LocalDateTime; @@ -85,6 +86,12 @@ public List getAnswers() { return answers; } + public void validateOwner(NsUser loginUser) throws CannotDeleteException { + if (!this.isOwner(loginUser)) { + throw new CannotDeleteException("์งˆ๋ฌธ์„ ์‚ญ์ œํ•  ๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค."); + } + } + @Override public String toString() { return "Question [id=" + getId() + ", title=" + title + ", contents=" + contents + ", writer=" + writer + "]"; diff --git a/src/main/java/nextstep/qna/service/QnAService.java b/src/main/java/nextstep/qna/service/QnAService.java index 5741c84d65..9a8719d072 100644 --- a/src/main/java/nextstep/qna/service/QnAService.java +++ b/src/main/java/nextstep/qna/service/QnAService.java @@ -26,19 +26,16 @@ public class QnAService { @Transactional public void deleteQuestion(NsUser loginUser, long questionId) throws CannotDeleteException { Question question = questionRepository.findById(questionId).orElseThrow(NotFoundException::new); - if (!question.isOwner(loginUser)) { - throw new CannotDeleteException("์งˆ๋ฌธ์„ ์‚ญ์ œํ•  ๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค."); - } + question.validateOwner(loginUser); List answers = question.getAnswers(); for (Answer answer : answers) { - if (!answer.isOwner(loginUser)) { - throw new CannotDeleteException("๋‹ค๋ฅธ ์‚ฌ๋žŒ์ด ์“ด ๋‹ต๋ณ€์ด ์žˆ์–ด ์‚ญ์ œํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); - } + answer.validateAnswerOwner(loginUser); } List deleteHistories = new ArrayList<>(); question.setDeleted(true); + deleteHistories.add(new DeleteHistory(ContentType.QUESTION, questionId, question.getWriter(), LocalDateTime.now())); for (Answer answer : answers) { answer.setDeleted(true); diff --git a/src/test/java/nextstep/qna/domain/AnswerTest.java b/src/test/java/nextstep/qna/domain/AnswerTest.java index 8e80ffb429..174b8cee6a 100644 --- a/src/test/java/nextstep/qna/domain/AnswerTest.java +++ b/src/test/java/nextstep/qna/domain/AnswerTest.java @@ -1,8 +1,18 @@ package nextstep.qna.domain; +import nextstep.qna.CannotDeleteException; import nextstep.users.domain.NsUserTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; 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 ๋‹ค๋ฅธ_์‚ฌ์šฉ์ž๊ฐ€_์ž‘์„ฑํ•œ_๋‹ต๋ณ€์ด_์กด์žฌํ•˜๋ฉด_์—๋Ÿฌ๋ฐœ์ƒ(){ + Assertions.assertThrows(CannotDeleteException.class, () -> { + A1.validateAnswerOwner(NsUserTest.SANJIGI); + }); + } } diff --git a/src/test/java/nextstep/qna/domain/QuestionTest.java b/src/test/java/nextstep/qna/domain/QuestionTest.java index 3b87823963..893a529f5b 100644 --- a/src/test/java/nextstep/qna/domain/QuestionTest.java +++ b/src/test/java/nextstep/qna/domain/QuestionTest.java @@ -1,8 +1,21 @@ package nextstep.qna.domain; +import nextstep.qna.CannotDeleteException; import nextstep.users.domain.NsUserTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; 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 ๊ธ€์“ด์ด๊ฐ€_๋กœ๊ทธ์ธํ•œ_์œ ์ €์™€_๊ฐ™์ง€์•Š์œผ๋ฉด_์—๋Ÿฌ๋ฐœ์ƒ(){ + Assertions.assertThrows(CannotDeleteException.class, () -> { + Q1.validateOwner(NsUserTest.SANJIGI); + }); + } + + + } From 9c9d031ddba692573dd58b806b55f74304d5ab95 Mon Sep 17 00:00:00 2001 From: CHANHAN <130114269+chanani@users.noreply.github.com> Date: Tue, 25 Nov 2025 15:22:58 +0900 Subject: [PATCH 04/16] =?UTF-8?q?refactor=20:=20Question=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=EC=9D=98=20=EC=9D=B8=EC=8A=A4=ED=84=B4=EC=8A=A4=20?= =?UTF-8?q?=EB=B3=80=EC=88=98(answer)=20=ED=99=9C=EC=9A=A9=ED=95=B4=20?= =?UTF-8?q?=EC=A7=81=EC=A0=91=20Answer=20=EA=B0=9D=EC=B2=B4=EC=9D=98=20val?= =?UTF-8?q?idateAnswerOwner=20=EB=A9=94=EC=84=9C=EB=93=9C=20=ED=98=B8?= =?UTF-8?q?=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++++ src/main/java/nextstep/qna/domain/Question.java | 9 ++++++++- src/main/java/nextstep/qna/service/QnAService.java | 7 +------ src/test/java/nextstep/qna/domain/QuestionTest.java | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4985061663..531dd84bf9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ # ํ•™์Šต ๊ด€๋ฆฌ ์‹œ์Šคํ…œ(Learning Management System) + +## ๋‹จ๊ณ„๋ณ„ ๋ฌธ์„œ +- [๐Ÿš€ 1๋‹จ๊ณ„ - ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ ๋ฆฌํŒฉํ„ฐ๋ง](./docs/01-refactoring.md) + ## ์ง„ํ–‰ ๋ฐฉ๋ฒ• * ํ•™์Šต ๊ด€๋ฆฌ ์‹œ์Šคํ…œ์˜ ์ˆ˜๊ฐ•์‹ ์ฒญ ์š”๊ตฌ์‚ฌํ•ญ์„ ํŒŒ์•…ํ•œ๋‹ค. * ์š”๊ตฌ์‚ฌํ•ญ์— ๋Œ€ํ•œ ๊ตฌํ˜„์„ ์™„๋ฃŒํ•œ ํ›„ ์ž์‹ ์˜ github ์•„์ด๋””์— ํ•ด๋‹นํ•˜๋Š” ๋ธŒ๋žœ์น˜์— Pull Request(์ดํ•˜ PR)๋ฅผ ํ†ตํ•ด ์ฝ”๋“œ ๋ฆฌ๋ทฐ ์š”์ฒญ์„ ํ•œ๋‹ค. diff --git a/src/main/java/nextstep/qna/domain/Question.java b/src/main/java/nextstep/qna/domain/Question.java index 773fb55e84..acd773571d 100644 --- a/src/main/java/nextstep/qna/domain/Question.java +++ b/src/main/java/nextstep/qna/domain/Question.java @@ -86,7 +86,14 @@ public List getAnswers() { return answers; } - public void validateOwner(NsUser loginUser) throws CannotDeleteException { + public void validateDeletable(NsUser loginUser) throws CannotDeleteException { + validateOwner(loginUser); + for (Answer answer : this.answers) { + answer.validateAnswerOwner(loginUser); + } + } + + private void validateOwner(NsUser loginUser) throws CannotDeleteException { if (!this.isOwner(loginUser)) { throw new CannotDeleteException("์งˆ๋ฌธ์„ ์‚ญ์ œํ•  ๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค."); } diff --git a/src/main/java/nextstep/qna/service/QnAService.java b/src/main/java/nextstep/qna/service/QnAService.java index 9a8719d072..f92e1f0743 100644 --- a/src/main/java/nextstep/qna/service/QnAService.java +++ b/src/main/java/nextstep/qna/service/QnAService.java @@ -26,12 +26,7 @@ public class QnAService { @Transactional public void deleteQuestion(NsUser loginUser, long questionId) throws CannotDeleteException { Question question = questionRepository.findById(questionId).orElseThrow(NotFoundException::new); - question.validateOwner(loginUser); - - List answers = question.getAnswers(); - for (Answer answer : answers) { - answer.validateAnswerOwner(loginUser); - } + question.validateDeletable(loginUser); List deleteHistories = new ArrayList<>(); question.setDeleted(true); diff --git a/src/test/java/nextstep/qna/domain/QuestionTest.java b/src/test/java/nextstep/qna/domain/QuestionTest.java index 893a529f5b..98a9547314 100644 --- a/src/test/java/nextstep/qna/domain/QuestionTest.java +++ b/src/test/java/nextstep/qna/domain/QuestionTest.java @@ -12,7 +12,7 @@ public class QuestionTest { @Test void ๊ธ€์“ด์ด๊ฐ€_๋กœ๊ทธ์ธํ•œ_์œ ์ €์™€_๊ฐ™์ง€์•Š์œผ๋ฉด_์—๋Ÿฌ๋ฐœ์ƒ(){ Assertions.assertThrows(CannotDeleteException.class, () -> { - Q1.validateOwner(NsUserTest.SANJIGI); + Q1.validateDeletable(NsUserTest.SANJIGI); }); } From 625a8958be4439859aa132964aaed17b39d75e63 Mon Sep 17 00:00:00 2001 From: CHANHAN <130114269+chanani@users.noreply.github.com> Date: Tue, 25 Nov 2025 17:29:03 +0900 Subject: [PATCH 05/16] =?UTF-8?q?refactor=20:=20=EC=A7=88=EB=AC=B8,=20?= =?UTF-8?q?=EB=8B=B5=EB=B3=80=20=EC=82=AD=EC=A0=9C=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?Question=20=EA=B0=9D=EC=B2=B4=EB=A1=9C=20=EC=9D=B4=EB=8F=99(Del?= =?UTF-8?q?eted=20=EA=B0=92=EC=9D=84=20=EB=B3=80=EA=B2=BD=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=A1=9C=EC=A7=81=EC=9D=B4=20=ED=8F=AC=ED=95=A8?= =?UTF-8?q?=EB=90=98=EC=96=B4=20=EC=9E=88=EC=96=B4=EC=84=9C=20=EC=96=B4?= =?UTF-8?q?=EB=96=BB=EA=B2=8C=20=EC=B2=98=EB=A6=AC=ED=95=98=EB=A9=B4=20?= =?UTF-8?q?=EC=A2=8B=EC=9D=84=EC=A7=80=20=EA=B3=A0=EB=AF=BC=EC=A4=91)=20?= =?UTF-8?q?=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/nextstep/qna/domain/Answer.java | 4 ++++ .../java/nextstep/qna/domain/Question.java | 22 +++++++++++++++++++ .../java/nextstep/qna/service/QnAService.java | 10 ++------- .../java/nextstep/qna/domain/AnswerTest.java | 13 +++++++++-- .../nextstep/qna/domain/QuestionTest.java | 15 +++++++++++-- 5 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/main/java/nextstep/qna/domain/Answer.java b/src/main/java/nextstep/qna/domain/Answer.java index 8899ad68ca..826d7f8d47 100644 --- a/src/main/java/nextstep/qna/domain/Answer.java +++ b/src/main/java/nextstep/qna/domain/Answer.java @@ -53,6 +53,10 @@ public Answer setDeleted(boolean deleted) { return this; } + public void updateDeleted(){ + this.deleted = true; + } + public boolean isDeleted() { return deleted; } diff --git a/src/main/java/nextstep/qna/domain/Question.java b/src/main/java/nextstep/qna/domain/Question.java index acd773571d..e0287246ac 100644 --- a/src/main/java/nextstep/qna/domain/Question.java +++ b/src/main/java/nextstep/qna/domain/Question.java @@ -99,8 +99,30 @@ private void validateOwner(NsUser loginUser) throws CannotDeleteException { } } + public List delete(long questionId) { + updateDeleted(); + + List deleteHistories = new ArrayList<>(); + deleteHistories.add(new DeleteHistory(ContentType.QUESTION, questionId, this.writer, LocalDateTime.now())); + addDeleteAnswerHistory(deleteHistories); + + return deleteHistories; + } + + private void addDeleteAnswerHistory(List deleteHistories) { + for (Answer answer : this.answers) { + answer.updateDeleted(); + deleteHistories.add(new DeleteHistory(ContentType.ANSWER, answer.getId(), answer.getWriter(), LocalDateTime.now())); + } + } + + private void updateDeleted() { + this.deleted = true; + } + @Override public String toString() { return "Question [id=" + getId() + ", title=" + title + ", contents=" + contents + ", writer=" + writer + "]"; } + } diff --git a/src/main/java/nextstep/qna/service/QnAService.java b/src/main/java/nextstep/qna/service/QnAService.java index f92e1f0743..8c1c212920 100644 --- a/src/main/java/nextstep/qna/service/QnAService.java +++ b/src/main/java/nextstep/qna/service/QnAService.java @@ -28,14 +28,8 @@ public void deleteQuestion(NsUser loginUser, long questionId) throws CannotDelet Question question = questionRepository.findById(questionId).orElseThrow(NotFoundException::new); question.validateDeletable(loginUser); - List deleteHistories = new ArrayList<>(); - question.setDeleted(true); - - deleteHistories.add(new DeleteHistory(ContentType.QUESTION, questionId, question.getWriter(), LocalDateTime.now())); - for (Answer answer : answers) { - answer.setDeleted(true); - deleteHistories.add(new DeleteHistory(ContentType.ANSWER, answer.getId(), answer.getWriter(), LocalDateTime.now())); - } + List deleteHistories = question.delete(questionId); + deleteHistoryService.saveAll(deleteHistories); } } diff --git a/src/test/java/nextstep/qna/domain/AnswerTest.java b/src/test/java/nextstep/qna/domain/AnswerTest.java index 174b8cee6a..c9358a94e1 100644 --- a/src/test/java/nextstep/qna/domain/AnswerTest.java +++ b/src/test/java/nextstep/qna/domain/AnswerTest.java @@ -2,17 +2,26 @@ import nextstep.qna.CannotDeleteException; import nextstep.users.domain.NsUserTest; -import org.junit.jupiter.api.Assertions; +import org.assertj.core.api.Assertions; 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 ๋‹ค๋ฅธ_์‚ฌ์šฉ์ž๊ฐ€_์ž‘์„ฑํ•œ_๋‹ต๋ณ€์ด_์กด์žฌํ•˜๋ฉด_์—๋Ÿฌ๋ฐœ์ƒ(){ - Assertions.assertThrows(CannotDeleteException.class, () -> { + assertThrows(CannotDeleteException.class, () -> { A1.validateAnswerOwner(NsUserTest.SANJIGI); }); } + + @Test + void ๋‹ต๋ณ€์‚ญ์ œ(){ + A1.updateDeleted(); + assertThat(A1.isDeleted()).isTrue(); + } } diff --git a/src/test/java/nextstep/qna/domain/QuestionTest.java b/src/test/java/nextstep/qna/domain/QuestionTest.java index 98a9547314..1c9c4d365c 100644 --- a/src/test/java/nextstep/qna/domain/QuestionTest.java +++ b/src/test/java/nextstep/qna/domain/QuestionTest.java @@ -2,20 +2,31 @@ import nextstep.qna.CannotDeleteException; import nextstep.users.domain.NsUserTest; -import org.junit.jupiter.api.Assertions; 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 ๊ธ€์“ด์ด๊ฐ€_๋กœ๊ทธ์ธํ•œ_์œ ์ €์™€_๊ฐ™์ง€์•Š์œผ๋ฉด_์—๋Ÿฌ๋ฐœ์ƒ(){ - Assertions.assertThrows(CannotDeleteException.class, () -> { + assertThrows(CannotDeleteException.class, () -> { Q1.validateDeletable(NsUserTest.SANJIGI); }); } + @Test + void ์งˆ๋ฌธ_๋‹ต๊ธ€_์‚ญ์ œ_๋ชฉ๋ก_์กฐํšŒ(){ + List deleteHistories = Q1.delete(1L); + assertThat(deleteHistories).hasSize(1); + } + + } From 188c9d7452983515e3c6d25ed0d2dc0c266df416 Mon Sep 17 00:00:00 2001 From: CHANHAN <130114269+chanani@users.noreply.github.com> Date: Tue, 25 Nov 2025 17:59:15 +0900 Subject: [PATCH 06/16] =?UTF-8?q?refactor=20:=20Question=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EC=9D=98=20List=20=EB=B3=80=EC=88=98?= =?UTF-8?q?=20=ED=8F=AC=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/nextstep/qna/domain/Answers.java | 34 +++++++++++++++++++ .../java/nextstep/qna/domain/Question.java | 16 ++++----- .../java/nextstep/qna/service/QnAService.java | 2 -- .../java/nextstep/qna/domain/AnswerTest.java | 1 - 4 files changed, 40 insertions(+), 13 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..33d5f42b56 --- /dev/null +++ b/src/main/java/nextstep/qna/domain/Answers.java @@ -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 { + + private List answers = new ArrayList<>(); + + public void add(Answer answer) { + this.answers.add(answer); + } + + public List getAnswers() { + return answers; + } + + public void validateAnswerOwner(NsUser loginUser) throws CannotDeleteException { + for (Answer answer : this.answers) { + answer.validateAnswerOwner(loginUser); + } + } + + public void addDeleteAnswerHistory(List deleteHistories) { + for (Answer answer : this.answers) { + answer.updateDeleted(); + deleteHistories.add(new DeleteHistory(ContentType.ANSWER, answer.getId(), answer.getWriter(), LocalDateTime.now())); + } + } +} diff --git a/src/main/java/nextstep/qna/domain/Question.java b/src/main/java/nextstep/qna/domain/Question.java index e0287246ac..0f7a177a21 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 = new Answers(); private boolean deleted = false; @@ -66,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) { @@ -83,14 +83,12 @@ public boolean isDeleted() { } public List getAnswers() { - return answers; + return answers.getAnswers(); } public void validateDeletable(NsUser loginUser) throws CannotDeleteException { validateOwner(loginUser); - for (Answer answer : this.answers) { - answer.validateAnswerOwner(loginUser); - } + answers.validateAnswerOwner(loginUser); } private void validateOwner(NsUser loginUser) throws CannotDeleteException { @@ -100,6 +98,7 @@ private void validateOwner(NsUser loginUser) throws CannotDeleteException { } public List delete(long questionId) { + // todo 2๊ฐœ์˜ ์—ญํ•™์„ ํ•˜๊ณ  ์žˆ๋‹ค๊ณ  ๋А๊ปด์ง‘๋‹ˆ๋‹ค. deleted ์ƒํƒœ๋ฅผ Setter ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ•ด์•ผ๋ ์ง€ ๊ณ ๋ฏผ์ž…๋‹ˆ๋‹ค. updateDeleted(); List deleteHistories = new ArrayList<>(); @@ -110,10 +109,7 @@ public List delete(long questionId) { } private void addDeleteAnswerHistory(List deleteHistories) { - for (Answer answer : this.answers) { - answer.updateDeleted(); - deleteHistories.add(new DeleteHistory(ContentType.ANSWER, answer.getId(), answer.getWriter(), LocalDateTime.now())); - } + this.answers.addDeleteAnswerHistory(deleteHistories); } private void updateDeleted() { diff --git a/src/main/java/nextstep/qna/service/QnAService.java b/src/main/java/nextstep/qna/service/QnAService.java index 8c1c212920..d26d49e05b 100644 --- a/src/main/java/nextstep/qna/service/QnAService.java +++ b/src/main/java/nextstep/qna/service/QnAService.java @@ -8,8 +8,6 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.time.LocalDateTime; -import java.util.ArrayList; import java.util.List; @Service("qnaService") diff --git a/src/test/java/nextstep/qna/domain/AnswerTest.java b/src/test/java/nextstep/qna/domain/AnswerTest.java index c9358a94e1..63f8612b25 100644 --- a/src/test/java/nextstep/qna/domain/AnswerTest.java +++ b/src/test/java/nextstep/qna/domain/AnswerTest.java @@ -2,7 +2,6 @@ import nextstep.qna.CannotDeleteException; import nextstep.users.domain.NsUserTest; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.*; From 8312ece733be17e928efe25f96e105e91bca00af Mon Sep 17 00:00:00 2001 From: CHANHAN <130114269+chanani@users.noreply.github.com> Date: Wed, 26 Nov 2025 14:30:18 +0900 Subject: [PATCH 07/16] =?UTF-8?q?docs=20:=20=ED=97=B7=EA=B0=88=EB=A6=AC?= =?UTF-8?q?=EB=8A=94=20=EB=82=B4=EC=9A=A9=20Todo=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/01-refactoring.md | 22 +++++++++---------- .../java/nextstep/qna/domain/Question.java | 2 +- .../java/nextstep/qna/service/QnAService.java | 2 -- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/docs/01-refactoring.md b/docs/01-refactoring.md index 13ff04b7c6..d66f3766bf 100644 --- a/docs/01-refactoring.md +++ b/docs/01-refactoring.md @@ -19,19 +19,19 @@ ## ์งˆ๋ฌธ ์‚ญ์ œํ•˜๊ธฐ ์š”๊ตฌ์‚ฌํ•ญ -- [ ] ์งˆ๋ฌธ ๋ฐ์ดํ„ฐ๋ฅผ ์™„์ „ํžˆ ์‚ญ์ œํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ๋ฐ์ดํ„ฐ์˜ ์ƒํƒœ๋ฅผ ์‚ญ์ œ ์ƒํƒœ(deleted - boolean type)๋กœ ๋ณ€๊ฒฝํ•œ๋‹ค. -- [ ] ๋กœ๊ทธ์ธ ์‚ฌ์šฉ์ž์™€ ์งˆ๋ฌธํ•œ ์‚ฌ๋žŒ์ด ๊ฐ™์€ ๊ฒฝ์šฐ ์‚ญ์ œ ๊ฐ€๋Šฅํ•˜๋‹ค. -- [ ] ๋‹ต๋ณ€์ด ์—†๋Š” ๊ฒฝ์šฐ ์‚ญ์ œ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค. -- [ ] ์งˆ๋ฌธ์ž์™€ ๋‹ต๋ณ€ ๊ธ€์˜ ๋ชจ๋“  ๋‹ต๋ณ€์ž๊ฐ€ ๊ฐ™์€ ๊ฒฝ์šฐ ์‚ญ์ œ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค. -- [ ] ์งˆ๋ฌธ์„ ์‚ญ์ œํ•  ๋•Œ ๋‹ต๋ณ€ ๋˜ํ•œ ์‚ญ์ œํ•ด์•ผ ํ•˜๋ฉฐ, ๋‹ต๋ณ€์˜ ์‚ญ์ œ ๋˜ํ•œ ์‚ญ์ œ ์ƒํƒœ(deleted)๋ฅผ ๋ณ€๊ฒฝํ•œ๋‹ค. -- [ ] ์งˆ๋ฌธ์ž์™€ ๋‹ต๋ณ€์ž๊ฐ€ ๋‹ค๋ฅธ ๊ฒฝ์šฐ ๋‹ต๋ณ€์„ ์‚ญ์ œํ•  ์ˆ˜ ์—†๋‹ค. -- [ ] ์งˆ๋ฌธ๊ณผ ๋‹ต๋ณ€ ์‚ญ์ œ ์ด๋ ฅ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ DeleteHistory๋ฅผ ํ™œ์šฉํ•ด ๋‚จ๊ธด๋‹ค. +- [x] ์งˆ๋ฌธ ๋ฐ์ดํ„ฐ๋ฅผ ์™„์ „ํžˆ ์‚ญ์ œํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ๋ฐ์ดํ„ฐ์˜ ์ƒํƒœ๋ฅผ ์‚ญ์ œ ์ƒํƒœ(deleted - boolean type)๋กœ ๋ณ€๊ฒฝํ•œ๋‹ค. +- [x] ๋กœ๊ทธ์ธ ์‚ฌ์šฉ์ž์™€ ์งˆ๋ฌธํ•œ ์‚ฌ๋žŒ์ด ๊ฐ™์€ ๊ฒฝ์šฐ ์‚ญ์ œ ๊ฐ€๋Šฅํ•˜๋‹ค. +- [x] ๋‹ต๋ณ€์ด ์—†๋Š” ๊ฒฝ์šฐ ์‚ญ์ œ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค. +- [x] ์งˆ๋ฌธ์ž์™€ ๋‹ต๋ณ€ ๊ธ€์˜ ๋ชจ๋“  ๋‹ต๋ณ€์ž๊ฐ€ ๊ฐ™์€ ๊ฒฝ์šฐ ์‚ญ์ œ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค. +- [x] ์งˆ๋ฌธ์„ ์‚ญ์ œํ•  ๋•Œ ๋‹ต๋ณ€ ๋˜ํ•œ ์‚ญ์ œํ•ด์•ผ ํ•˜๋ฉฐ, ๋‹ต๋ณ€์˜ ์‚ญ์ œ ๋˜ํ•œ ์‚ญ์ œ ์ƒํƒœ(deleted)๋ฅผ ๋ณ€๊ฒฝํ•œ๋‹ค. +- [x] ์งˆ๋ฌธ์ž์™€ ๋‹ต๋ณ€์ž๊ฐ€ ๋‹ค๋ฅธ ๊ฒฝ์šฐ ๋‹ต๋ณ€์„ ์‚ญ์ œํ•  ์ˆ˜ ์—†๋‹ค. +- [x] ์งˆ๋ฌธ๊ณผ ๋‹ต๋ณ€ ์‚ญ์ œ ์ด๋ ฅ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ DeleteHistory๋ฅผ ํ™œ์šฉํ•ด ๋‚จ๊ธด๋‹ค. ## ๋ฆฌํŒฉํ„ฐ๋ง ์š”๊ตฌ์‚ฌํ•ญ -- [ ] nextstep.qna.service.QnaService์˜ deleteQuestion()๋Š” ์•ž์˜ ์งˆ๋ฌธ ์‚ญ์ œ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•œ ์ฝ”๋“œ์ด๋‹ค. +- [x] nextstep.qna.service.QnaService์˜ deleteQuestion()๋Š” ์•ž์˜ ์งˆ๋ฌธ ์‚ญ์ œ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•œ ์ฝ”๋“œ์ด๋‹ค. ์ด ๋ฉ”์†Œ๋“œ๋Š” ๋‹จ์œ„ ํ…Œ์ŠคํŠธํ•˜๊ธฐ ์–ด๋ ค์šด ์ฝ”๋“œ์™€ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ๊ฐ€๋Šฅํ•œ ์ฝ”๋“œ๊ฐ€ ์„ž์—ฌ ์žˆ๋‹ค. -- [ ] QnaService์˜ deleteQuestion() ๋ฉ”์„œ๋“œ์— ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ๊ฐ€๋Šฅํ•œ ์ฝ”๋“œ(ํ•ต์‹ฌ ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง)๋ฅผ ๋„๋ฉ”์ธ ๋ชจ๋ธ ๊ฐ์ฒด์— ๊ตฌํ˜„ํ•œ๋‹ค. -- [ ] QnaService์˜ ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง์„ ๋„๋ฉ”์ธ ๋ชจ๋ธ๋กœ ์ด๋™ํ•˜๋Š” ๋ฆฌํŒฉํ„ฐ๋ง์„ ์ง„ํ–‰ํ•  ๋•Œ TDD๋กœ ๊ตฌํ˜„ํ•œ๋‹ค. -- [ ] QnaService์˜ deleteQuestion() ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•œ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋Š” src/test/java ํด๋” nextstep.qna.service.QnaServiceTest์ด๋‹ค. +- [x] QnaService์˜ deleteQuestion() ๋ฉ”์„œ๋“œ์— ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ๊ฐ€๋Šฅํ•œ ์ฝ”๋“œ(ํ•ต์‹ฌ ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง)๋ฅผ ๋„๋ฉ”์ธ ๋ชจ๋ธ ๊ฐ์ฒด์— ๊ตฌํ˜„ํ•œ๋‹ค. +- [x] QnaService์˜ ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง์„ ๋„๋ฉ”์ธ ๋ชจ๋ธ๋กœ ์ด๋™ํ•˜๋Š” ๋ฆฌํŒฉํ„ฐ๋ง์„ ์ง„ํ–‰ํ•  ๋•Œ TDD๋กœ ๊ตฌํ˜„ํ•œ๋‹ค. +- [x] QnaService์˜ deleteQuestion() ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•œ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋Š” src/test/java ํด๋” nextstep.qna.service.QnaServiceTest์ด๋‹ค. ๋„๋ฉ”์ธ ๋ชจ๋ธ๋กœ ๋กœ์ง์„ ์ด๋™ํ•œ ํ›„์—๋„ QnaServiceTest์˜ ๋ชจ๋“  ํ…Œ์ŠคํŠธ๋Š” ํ†ต๊ณผํ•ด์•ผ ํ•œ๋‹ค. \ No newline at end of file diff --git a/src/main/java/nextstep/qna/domain/Question.java b/src/main/java/nextstep/qna/domain/Question.java index 0f7a177a21..474fd63f18 100644 --- a/src/main/java/nextstep/qna/domain/Question.java +++ b/src/main/java/nextstep/qna/domain/Question.java @@ -98,7 +98,7 @@ private void validateOwner(NsUser loginUser) throws CannotDeleteException { } public List delete(long questionId) { - // todo 2๊ฐœ์˜ ์—ญํ•™์„ ํ•˜๊ณ  ์žˆ๋‹ค๊ณ  ๋А๊ปด์ง‘๋‹ˆ๋‹ค. deleted ์ƒํƒœ๋ฅผ Setter ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ•ด์•ผ๋ ์ง€ ๊ณ ๋ฏผ์ž…๋‹ˆ๋‹ค. + // todo 2๊ฐœ์˜ ์—ญํ• ์„ ํ•˜๊ณ  ์žˆ๋‹ค๊ณ  ๋А๊ปด์ง‘๋‹ˆ๋‹ค. deleted ์ƒํƒœ๋ฅผ Setter ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ•ด์•ผ๋ ์ง€ ๊ณ ๋ฏผ์ž…๋‹ˆ๋‹ค. updateDeleted(); List deleteHistories = new ArrayList<>(); diff --git a/src/main/java/nextstep/qna/service/QnAService.java b/src/main/java/nextstep/qna/service/QnAService.java index d26d49e05b..fbf809afbb 100644 --- a/src/main/java/nextstep/qna/service/QnAService.java +++ b/src/main/java/nextstep/qna/service/QnAService.java @@ -25,9 +25,7 @@ public class QnAService { public void deleteQuestion(NsUser loginUser, long questionId) throws CannotDeleteException { Question question = questionRepository.findById(questionId).orElseThrow(NotFoundException::new); question.validateDeletable(loginUser); - List deleteHistories = question.delete(questionId); - deleteHistoryService.saveAll(deleteHistories); } } From f1b35477eab73236ec0069e7174399e7dff924f6 Mon Sep 17 00:00:00 2001 From: CHANHAN <130114269+chanani@users.noreply.github.com> Date: Wed, 26 Nov 2025 19:53:47 +0900 Subject: [PATCH 08/16] =?UTF-8?q?refactor=20:=20=EA=B3=B5=EB=8F=99?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=82=AC=EC=9A=A9=EB=90=98=EB=8A=94=20cre?= =?UTF-8?q?atedDate,=20updatedDate,=20delted=EB=A5=BC=20BaseModel=EB=A1=9C?= =?UTF-8?q?=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 | 12 ++---------- src/main/java/nextstep/qna/domain/BaseModel.java | 12 ++++++++++++ src/main/java/nextstep/qna/domain/Question.java | 8 +------- 3 files changed, 15 insertions(+), 17 deletions(-) create mode 100644 src/main/java/nextstep/qna/domain/BaseModel.java diff --git a/src/main/java/nextstep/qna/domain/Answer.java b/src/main/java/nextstep/qna/domain/Answer.java index 826d7f8d47..fd40b632ed 100644 --- a/src/main/java/nextstep/qna/domain/Answer.java +++ b/src/main/java/nextstep/qna/domain/Answer.java @@ -5,9 +5,7 @@ import nextstep.qna.UnAuthorizedException; import nextstep.users.domain.NsUser; -import java.time.LocalDateTime; - -public class Answer { +public class Answer extends BaseModel { private Long id; private NsUser writer; @@ -16,12 +14,6 @@ public class Answer { private String contents; - private boolean deleted = false; - - private LocalDateTime createdDate = LocalDateTime.now(); - - private LocalDateTime updatedDate; - public Answer() { } @@ -53,7 +45,7 @@ public Answer setDeleted(boolean deleted) { return this; } - public void updateDeleted(){ + public void updateDeleted() { this.deleted = true; } diff --git a/src/main/java/nextstep/qna/domain/BaseModel.java b/src/main/java/nextstep/qna/domain/BaseModel.java new file mode 100644 index 0000000000..8fc2f5a3c9 --- /dev/null +++ b/src/main/java/nextstep/qna/domain/BaseModel.java @@ -0,0 +1,12 @@ +package nextstep.qna.domain; + +import java.time.LocalDateTime; + +public abstract class BaseModel { + + public LocalDateTime createdDate = LocalDateTime.now(); + + public LocalDateTime updatedDate; + + public boolean deleted = false; +} diff --git a/src/main/java/nextstep/qna/domain/Question.java b/src/main/java/nextstep/qna/domain/Question.java index 474fd63f18..2fb718a5ca 100644 --- a/src/main/java/nextstep/qna/domain/Question.java +++ b/src/main/java/nextstep/qna/domain/Question.java @@ -7,7 +7,7 @@ import java.util.ArrayList; import java.util.List; -public class Question { +public class Question extends BaseModel { private Long id; private String title; @@ -18,12 +18,6 @@ public class Question { private Answers answers = new Answers(); - private boolean deleted = false; - - private LocalDateTime createdDate = LocalDateTime.now(); - - private LocalDateTime updatedDate; - public Question() { } From 54e1f6d975f79926b81e9b047730ae574e82e02e Mon Sep 17 00:00:00 2001 From: CHANHAN <130114269+chanani@users.noreply.github.com> Date: Wed, 26 Nov 2025 20:02:26 +0900 Subject: [PATCH 09/16] =?UTF-8?q?refactor=20:=20title,=20contents=20?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=20=ED=8F=AC=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/nextstep/qna/domain/Answer.java | 7 ++--- .../java/nextstep/qna/domain/Contents.java | 10 +++++++ .../java/nextstep/qna/domain/Question.java | 26 +++++-------------- src/main/java/nextstep/qna/domain/Title.java | 10 +++++++ 4 files changed, 28 insertions(+), 25 deletions(-) create mode 100644 src/main/java/nextstep/qna/domain/Contents.java create mode 100644 src/main/java/nextstep/qna/domain/Title.java diff --git a/src/main/java/nextstep/qna/domain/Answer.java b/src/main/java/nextstep/qna/domain/Answer.java index fd40b632ed..f54752b477 100644 --- a/src/main/java/nextstep/qna/domain/Answer.java +++ b/src/main/java/nextstep/qna/domain/Answer.java @@ -12,7 +12,7 @@ public class Answer extends BaseModel { private Question question; - private String contents; + private Contents contents; public Answer() { } @@ -33,7 +33,7 @@ public Answer(Long id, NsUser writer, Question question, String contents) { this.writer = writer; this.question = question; - this.contents = contents; + this.contents = new Contents(contents); } public Long getId() { @@ -61,9 +61,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/Contents.java b/src/main/java/nextstep/qna/domain/Contents.java new file mode 100644 index 0000000000..ff4993cdce --- /dev/null +++ b/src/main/java/nextstep/qna/domain/Contents.java @@ -0,0 +1,10 @@ +package nextstep.qna.domain; + +public class Contents { + + private String value; + + public Contents(String value) { + this.value = value; + } +} diff --git a/src/main/java/nextstep/qna/domain/Question.java b/src/main/java/nextstep/qna/domain/Question.java index 2fb718a5ca..6ad430e6c5 100644 --- a/src/main/java/nextstep/qna/domain/Question.java +++ b/src/main/java/nextstep/qna/domain/Question.java @@ -10,9 +10,9 @@ public class Question extends BaseModel { private Long id; - private String title; + private Title title; - private String contents; + private Contents contents; private NsUser writer; @@ -26,6 +26,10 @@ public Question(NsUser writer, String title, String contents) { } public Question(Long id, NsUser writer, String title, String contents) { + this(id, writer, new Title(title), new Contents(contents)); + } + + public Question(Long id, NsUser writer, Title title, Contents contents) { this.id = id; this.writer = writer; this.title = title; @@ -36,24 +40,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; } diff --git a/src/main/java/nextstep/qna/domain/Title.java b/src/main/java/nextstep/qna/domain/Title.java new file mode 100644 index 0000000000..448dcb4550 --- /dev/null +++ b/src/main/java/nextstep/qna/domain/Title.java @@ -0,0 +1,10 @@ +package nextstep.qna.domain; + +public class Title { + + private String value; + + public Title(String value) { + this.value = value; + } +} From c4db9bd33a01b9aded11556f263cb1afccdd52de Mon Sep 17 00:00:00 2001 From: CHANHAN <130114269+chanani@users.noreply.github.com> Date: Wed, 26 Nov 2025 20:05:10 +0900 Subject: [PATCH 10/16] =?UTF-8?q?refactor=20:=20delete()=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=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/Question.java | 4 ++-- src/main/java/nextstep/qna/service/QnAService.java | 2 +- src/test/java/nextstep/qna/domain/QuestionTest.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/nextstep/qna/domain/Question.java b/src/main/java/nextstep/qna/domain/Question.java index 6ad430e6c5..481065b0e1 100644 --- a/src/main/java/nextstep/qna/domain/Question.java +++ b/src/main/java/nextstep/qna/domain/Question.java @@ -77,12 +77,12 @@ private void validateOwner(NsUser loginUser) throws CannotDeleteException { } } - public List delete(long questionId) { + public List delete() { // todo 2๊ฐœ์˜ ์—ญํ• ์„ ํ•˜๊ณ  ์žˆ๋‹ค๊ณ  ๋А๊ปด์ง‘๋‹ˆ๋‹ค. deleted ์ƒํƒœ๋ฅผ Setter ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ•ด์•ผ๋ ์ง€ ๊ณ ๋ฏผ์ž…๋‹ˆ๋‹ค. updateDeleted(); List deleteHistories = new ArrayList<>(); - deleteHistories.add(new DeleteHistory(ContentType.QUESTION, questionId, this.writer, LocalDateTime.now())); + deleteHistories.add(new DeleteHistory(ContentType.QUESTION, this.id, this.writer, LocalDateTime.now())); addDeleteAnswerHistory(deleteHistories); return deleteHistories; diff --git a/src/main/java/nextstep/qna/service/QnAService.java b/src/main/java/nextstep/qna/service/QnAService.java index fbf809afbb..4cf7d669eb 100644 --- a/src/main/java/nextstep/qna/service/QnAService.java +++ b/src/main/java/nextstep/qna/service/QnAService.java @@ -25,7 +25,7 @@ public class QnAService { public void deleteQuestion(NsUser loginUser, long questionId) throws CannotDeleteException { Question question = questionRepository.findById(questionId).orElseThrow(NotFoundException::new); question.validateDeletable(loginUser); - List deleteHistories = question.delete(questionId); + List deleteHistories = question.delete(); deleteHistoryService.saveAll(deleteHistories); } } diff --git a/src/test/java/nextstep/qna/domain/QuestionTest.java b/src/test/java/nextstep/qna/domain/QuestionTest.java index 1c9c4d365c..357fec9e20 100644 --- a/src/test/java/nextstep/qna/domain/QuestionTest.java +++ b/src/test/java/nextstep/qna/domain/QuestionTest.java @@ -22,7 +22,7 @@ public class QuestionTest { @Test void ์งˆ๋ฌธ_๋‹ต๊ธ€_์‚ญ์ œ_๋ชฉ๋ก_์กฐํšŒ(){ - List deleteHistories = Q1.delete(1L); + List deleteHistories = Q1.delete(); assertThat(deleteHistories).hasSize(1); } From 400b772fdcdaddff0db2aff1ca5da620cebb2e14 Mon Sep 17 00:00:00 2001 From: CHANHAN <130114269+chanani@users.noreply.github.com> Date: Wed, 26 Nov 2025 22:27:04 +0900 Subject: [PATCH 11/16] =?UTF-8?q?refactor=20:=20=EA=B2=80=EC=A6=9D?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=EA=B3=BC=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=EB=B3=80=EA=B2=BD=ED=95=98=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=EC=9D=84=20=ED=95=A8=EA=BB=98=20=EA=B5=AC=ED=98=84,?= =?UTF-8?q?=20=EC=83=81=ED=83=9C=EB=A5=BC=20=EB=B3=80=EA=B2=BD=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=EC=99=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=82=B4=EC=97=AD=EC=9D=84=20=EB=82=A8=EA=B8=B0?= =?UTF-8?q?=EB=8A=94=20history=EB=A5=BC=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/Answers.java | 2 +- src/main/java/nextstep/qna/domain/Question.java | 13 +++++-------- src/main/java/nextstep/qna/service/QnAService.java | 5 +++-- src/test/java/nextstep/qna/domain/QuestionTest.java | 13 ++++--------- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/main/java/nextstep/qna/domain/Answers.java b/src/main/java/nextstep/qna/domain/Answers.java index 33d5f42b56..39429c64d6 100644 --- a/src/main/java/nextstep/qna/domain/Answers.java +++ b/src/main/java/nextstep/qna/domain/Answers.java @@ -22,12 +22,12 @@ public List getAnswers() { public void validateAnswerOwner(NsUser loginUser) throws CannotDeleteException { for (Answer answer : this.answers) { answer.validateAnswerOwner(loginUser); + answer.updateDeleted(); } } public void addDeleteAnswerHistory(List deleteHistories) { for (Answer answer : this.answers) { - answer.updateDeleted(); deleteHistories.add(new DeleteHistory(ContentType.ANSWER, answer.getId(), answer.getWriter(), LocalDateTime.now())); } } diff --git a/src/main/java/nextstep/qna/domain/Question.java b/src/main/java/nextstep/qna/domain/Question.java index 481065b0e1..15f55097e2 100644 --- a/src/main/java/nextstep/qna/domain/Question.java +++ b/src/main/java/nextstep/qna/domain/Question.java @@ -66,25 +66,22 @@ public List getAnswers() { 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 delete() { - // todo 2๊ฐœ์˜ ์—ญํ• ์„ ํ•˜๊ณ  ์žˆ๋‹ค๊ณ  ๋А๊ปด์ง‘๋‹ˆ๋‹ค. deleted ์ƒํƒœ๋ฅผ Setter ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ•ด์•ผ๋ ์ง€ ๊ณ ๋ฏผ์ž…๋‹ˆ๋‹ค. + public void delete(NsUser loginUser) throws CannotDeleteException { + validateOwner(loginUser); updateDeleted(); + answers.validateAnswerOwner(loginUser); + } + public List toDeleteHistories(){ List deleteHistories = new ArrayList<>(); deleteHistories.add(new DeleteHistory(ContentType.QUESTION, this.id, this.writer, LocalDateTime.now())); addDeleteAnswerHistory(deleteHistories); - return deleteHistories; } diff --git a/src/main/java/nextstep/qna/service/QnAService.java b/src/main/java/nextstep/qna/service/QnAService.java index 4cf7d669eb..fe5ae4effb 100644 --- a/src/main/java/nextstep/qna/service/QnAService.java +++ b/src/main/java/nextstep/qna/service/QnAService.java @@ -24,8 +24,9 @@ public class QnAService { @Transactional public void deleteQuestion(NsUser loginUser, long questionId) throws CannotDeleteException { Question question = questionRepository.findById(questionId).orElseThrow(NotFoundException::new); - question.validateDeletable(loginUser); - List deleteHistories = question.delete(); + question.delete(loginUser); + + List deleteHistories = question.toDeleteHistories(); deleteHistoryService.saveAll(deleteHistories); } } diff --git a/src/test/java/nextstep/qna/domain/QuestionTest.java b/src/test/java/nextstep/qna/domain/QuestionTest.java index 357fec9e20..92c4a10b1e 100644 --- a/src/test/java/nextstep/qna/domain/QuestionTest.java +++ b/src/test/java/nextstep/qna/domain/QuestionTest.java @@ -4,7 +4,6 @@ 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.*; @@ -16,17 +15,13 @@ public class QuestionTest { @Test void ๊ธ€์“ด์ด๊ฐ€_๋กœ๊ทธ์ธํ•œ_์œ ์ €์™€_๊ฐ™์ง€์•Š์œผ๋ฉด_์—๋Ÿฌ๋ฐœ์ƒ(){ assertThrows(CannotDeleteException.class, () -> { - Q1.validateDeletable(NsUserTest.SANJIGI); + Q1.delete(NsUserTest.SANJIGI); }); } @Test - void ์งˆ๋ฌธ_๋‹ต๊ธ€_์‚ญ์ œ_๋ชฉ๋ก_์กฐํšŒ(){ - List deleteHistories = Q1.delete(); - assertThat(deleteHistories).hasSize(1); + void ์งˆ๋ฌธ_์‚ญ์ œ() throws CannotDeleteException { + Q1.delete(NsUserTest.JAVAJIGI); + assertThat(Q1.deleted).isTrue(); } - - - - } From 73effd22e99dbe66b4a87c8c8fc15a455b62eb60 Mon Sep 17 00:00:00 2001 From: CHANHAN <130114269+chanani@users.noreply.github.com> Date: Wed, 26 Nov 2025 22:41:05 +0900 Subject: [PATCH 12/16] =?UTF-8?q?feat=20:=20Answers=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=83=9D=EC=84=B1=20refactor?= =?UTF-8?q?=20:=20answer=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80,=20Question=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EB=82=B4=EB=B6=80=20=EC=88=98?= =?UTF-8?q?=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 | 8 ++++++-- .../java/nextstep/qna/domain/AnswerTest.java | 18 ++++++++++++++++++ .../java/nextstep/qna/domain/AnswersTest.java | 18 ++++++++++++++++++ .../java/nextstep/qna/domain/QuestionTest.java | 4 ++-- 4 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 src/test/java/nextstep/qna/domain/AnswersTest.java diff --git a/src/main/java/nextstep/qna/domain/Answer.java b/src/main/java/nextstep/qna/domain/Answer.java index f54752b477..b6fc631277 100644 --- a/src/main/java/nextstep/qna/domain/Answer.java +++ b/src/main/java/nextstep/qna/domain/Answer.java @@ -18,10 +18,14 @@ public Answer() { } public Answer(NsUser writer, Question question, String contents) { - this(null, writer, question, contents); + this(null, writer, question, new Contents(contents)); } public Answer(Long id, NsUser writer, Question question, String contents) { + this(id, writer, question, new Contents(contents)); + } + + public Answer(Long id, NsUser writer, Question question, Contents contents) { this.id = id; if (writer == null) { throw new UnAuthorizedException(); @@ -33,7 +37,7 @@ public Answer(Long id, NsUser writer, Question question, String contents) { this.writer = writer; this.question = question; - this.contents = new Contents(contents); + this.contents = contents; } public Long getId() { diff --git a/src/test/java/nextstep/qna/domain/AnswerTest.java b/src/test/java/nextstep/qna/domain/AnswerTest.java index 63f8612b25..ff35c68272 100644 --- a/src/test/java/nextstep/qna/domain/AnswerTest.java +++ b/src/test/java/nextstep/qna/domain/AnswerTest.java @@ -1,7 +1,11 @@ package nextstep.qna.domain; import nextstep.qna.CannotDeleteException; +import nextstep.qna.NotFoundException; +import nextstep.qna.UnAuthenticationException; +import nextstep.qna.UnAuthorizedException; import nextstep.users.domain.NsUserTest; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.*; @@ -23,4 +27,18 @@ public class AnswerTest { A1.updateDeleted(); assertThat(A1.isDeleted()).isTrue(); } + + @Test + void ์ž‘์„ฑ์ž๊ฐ€_null์ด๋ฉด_์—๋Ÿฌ๋ฐœ์ƒ(){ + Assertions.assertThrows(UnAuthorizedException.class, () -> { + new Answer(null, QuestionTest.Q1, "Contents1"); + }); + } + + @Test + void ์งˆ๋ฌธ์ด_null์ด๋ฉด_์—๋Ÿฌ๋ฐœ์ƒ(){ + Assertions.assertThrows(NotFoundException.class, () -> { + new Answer(NsUserTest.JAVAJIGI, null, "Contents1"); + }); + } } diff --git a/src/test/java/nextstep/qna/domain/AnswersTest.java b/src/test/java/nextstep/qna/domain/AnswersTest.java new file mode 100644 index 0000000000..fd432885d4 --- /dev/null +++ b/src/test/java/nextstep/qna/domain/AnswersTest.java @@ -0,0 +1,18 @@ +package nextstep.qna.domain; + +import nextstep.users.domain.NsUserTest; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + + +class AnswersTest { + public static final Question Q1 = new Question(NsUserTest.JAVAJIGI, "title1", "contents1"); + + @Test + void ๋‹ต๋ณ€_์ƒ์„ฑ(){ + Answers answers = new Answers(); + answers.add(new Answer(NsUserTest.JAVAJIGI, Q1, "content1")); + Assertions.assertThat(answers.getAnswers()).hasSize(1); + } + +} \ No newline at end of file diff --git a/src/test/java/nextstep/qna/domain/QuestionTest.java b/src/test/java/nextstep/qna/domain/QuestionTest.java index 92c4a10b1e..85df638873 100644 --- a/src/test/java/nextstep/qna/domain/QuestionTest.java +++ b/src/test/java/nextstep/qna/domain/QuestionTest.java @@ -15,13 +15,13 @@ public class QuestionTest { @Test void ๊ธ€์“ด์ด๊ฐ€_๋กœ๊ทธ์ธํ•œ_์œ ์ €์™€_๊ฐ™์ง€์•Š์œผ๋ฉด_์—๋Ÿฌ๋ฐœ์ƒ(){ assertThrows(CannotDeleteException.class, () -> { - Q1.delete(NsUserTest.SANJIGI); + Q1.delete(Q2.getWriter()); }); } @Test void ์งˆ๋ฌธ_์‚ญ์ œ() throws CannotDeleteException { - Q1.delete(NsUserTest.JAVAJIGI); + Q1.delete(Q1.getWriter()); assertThat(Q1.deleted).isTrue(); } } From 797023cace278c9083ab9f85671bf5f9b0d9c10c Mon Sep 17 00:00:00 2001 From: CHANHAN <130114269+chanani@users.noreply.github.com> Date: Thu, 27 Nov 2025 09:09:24 +0900 Subject: [PATCH 13/16] =?UTF-8?q?refactor=20:=20updateDeleted()=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20private=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD,=20=ED=98=B8=EC=B6=9C=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=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 | 3 ++- src/main/java/nextstep/qna/domain/Answers.java | 2 +- src/main/java/nextstep/qna/domain/Question.java | 9 --------- src/test/java/nextstep/qna/domain/AnswerTest.java | 5 ++--- 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/main/java/nextstep/qna/domain/Answer.java b/src/main/java/nextstep/qna/domain/Answer.java index b6fc631277..d068f83de7 100644 --- a/src/main/java/nextstep/qna/domain/Answer.java +++ b/src/main/java/nextstep/qna/domain/Answer.java @@ -49,7 +49,7 @@ public Answer setDeleted(boolean deleted) { return this; } - public void updateDeleted() { + private void updateDeleted() { this.deleted = true; } @@ -74,6 +74,7 @@ public void validateAnswerOwner(NsUser loginUser) throws CannotDeleteException { if (!this.isOwner(loginUser)) { throw new CannotDeleteException("๋‹ค๋ฅธ ์‚ฌ๋žŒ์ด ์“ด ๋‹ต๋ณ€์ด ์žˆ์–ด ์‚ญ์ œํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); } + updateDeleted(); } @Override diff --git a/src/main/java/nextstep/qna/domain/Answers.java b/src/main/java/nextstep/qna/domain/Answers.java index 39429c64d6..f5982698d4 100644 --- a/src/main/java/nextstep/qna/domain/Answers.java +++ b/src/main/java/nextstep/qna/domain/Answers.java @@ -22,7 +22,7 @@ public List getAnswers() { public void validateAnswerOwner(NsUser loginUser) throws CannotDeleteException { for (Answer answer : this.answers) { answer.validateAnswerOwner(loginUser); - answer.updateDeleted(); + } } diff --git a/src/main/java/nextstep/qna/domain/Question.java b/src/main/java/nextstep/qna/domain/Question.java index 15f55097e2..d46cec1270 100644 --- a/src/main/java/nextstep/qna/domain/Question.java +++ b/src/main/java/nextstep/qna/domain/Question.java @@ -53,19 +53,10 @@ public boolean isOwner(NsUser loginUser) { return writer.equals(loginUser); } - public Question setDeleted(boolean deleted) { - this.deleted = deleted; - return this; - } - public boolean isDeleted() { return deleted; } - public List getAnswers() { - return answers.getAnswers(); - } - private void validateOwner(NsUser loginUser) throws CannotDeleteException { if (!this.isOwner(loginUser)) { throw new CannotDeleteException("์งˆ๋ฌธ์„ ์‚ญ์ œํ•  ๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค."); diff --git a/src/test/java/nextstep/qna/domain/AnswerTest.java b/src/test/java/nextstep/qna/domain/AnswerTest.java index ff35c68272..9a674727a5 100644 --- a/src/test/java/nextstep/qna/domain/AnswerTest.java +++ b/src/test/java/nextstep/qna/domain/AnswerTest.java @@ -2,7 +2,6 @@ import nextstep.qna.CannotDeleteException; import nextstep.qna.NotFoundException; -import nextstep.qna.UnAuthenticationException; import nextstep.qna.UnAuthorizedException; import nextstep.users.domain.NsUserTest; import org.junit.jupiter.api.Assertions; @@ -23,8 +22,8 @@ public class AnswerTest { } @Test - void ๋‹ต๋ณ€์‚ญ์ œ(){ - A1.updateDeleted(); + void ๋‹ต๋ณ€์‚ญ์ œ() throws CannotDeleteException { + A1.validateAnswerOwner(A1.getWriter()); assertThat(A1.isDeleted()).isTrue(); } From 660f24f79b67e1cdd10b894a8d89eaa4f9df5809 Mon Sep 17 00:00:00 2001 From: CHANHAN <130114269+chanani@users.noreply.github.com> Date: Thu, 27 Nov 2025 10:05:49 +0900 Subject: [PATCH 14/16] =?UTF-8?q?refactor=20:=20BaseModel=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EC=9D=98=20=EC=9D=B8=EC=8A=A4=ED=84=B4?= =?UTF-8?q?=EC=8A=A4=20=EB=B3=80=EC=88=98=20private=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD,=20=ED=95=84=EC=9A=94=ED=95=9C=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20protected=EB=A1=9C=20=EC=84=A0=EC=96=B8=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80=20=EB=82=B4=EC=97=90=EC=84=9C=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=20=EA=B0=80=EB=8A=A5=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/01-refactoring.md | 2 +- src/main/java/nextstep/qna/domain/Answer.java | 9 ++------- src/main/java/nextstep/qna/domain/Answers.java | 4 +++- src/main/java/nextstep/qna/domain/BaseModel.java | 14 +++++++++++--- src/main/java/nextstep/qna/domain/Question.java | 15 +++++++++------ .../java/nextstep/qna/domain/QuestionTest.java | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/docs/01-refactoring.md b/docs/01-refactoring.md index d66f3766bf..9bf8f783bd 100644 --- a/docs/01-refactoring.md +++ b/docs/01-refactoring.md @@ -2,7 +2,7 @@ *** ## ์ฝ”๋“œ ๋ฆฌ๋ทฐ -> PR ๋งํฌ : +> PR ๋งํฌ : [#790](https://github.com/next-step/java-lms/pull/790) ## ๋‚˜์˜ ํ•™์Šต ๋ชฉํ‘œ diff --git a/src/main/java/nextstep/qna/domain/Answer.java b/src/main/java/nextstep/qna/domain/Answer.java index d068f83de7..5c0ad1639c 100644 --- a/src/main/java/nextstep/qna/domain/Answer.java +++ b/src/main/java/nextstep/qna/domain/Answer.java @@ -44,17 +44,12 @@ public Long getId() { return id; } - public Answer setDeleted(boolean deleted) { - this.deleted = deleted; - return this; - } - private void updateDeleted() { - this.deleted = true; + deleted(); } public boolean isDeleted() { - return deleted; + return getDeleted(); } public boolean isOwner(NsUser writer) { diff --git a/src/main/java/nextstep/qna/domain/Answers.java b/src/main/java/nextstep/qna/domain/Answers.java index f5982698d4..38132c0ea5 100644 --- a/src/main/java/nextstep/qna/domain/Answers.java +++ b/src/main/java/nextstep/qna/domain/Answers.java @@ -26,9 +26,11 @@ public void validateAnswerOwner(NsUser loginUser) throws CannotDeleteException { } } - public void addDeleteAnswerHistory(List deleteHistories) { + public List addDeleteAnswerHistory() { + List deleteHistories = new ArrayList<>(); for (Answer answer : this.answers) { deleteHistories.add(new DeleteHistory(ContentType.ANSWER, answer.getId(), answer.getWriter(), LocalDateTime.now())); } + return deleteHistories; } } diff --git a/src/main/java/nextstep/qna/domain/BaseModel.java b/src/main/java/nextstep/qna/domain/BaseModel.java index 8fc2f5a3c9..59fbbba9db 100644 --- a/src/main/java/nextstep/qna/domain/BaseModel.java +++ b/src/main/java/nextstep/qna/domain/BaseModel.java @@ -4,9 +4,17 @@ public abstract class BaseModel { - public LocalDateTime createdDate = LocalDateTime.now(); + private LocalDateTime createdDate = LocalDateTime.now(); - public LocalDateTime updatedDate; + private LocalDateTime updatedDate; - public boolean deleted = false; + private boolean deleted = false; + + protected void deleted(){ + this.deleted = true; + } + + protected boolean getDeleted() { + return deleted; + } } diff --git a/src/main/java/nextstep/qna/domain/Question.java b/src/main/java/nextstep/qna/domain/Question.java index d46cec1270..ea8f41227a 100644 --- a/src/main/java/nextstep/qna/domain/Question.java +++ b/src/main/java/nextstep/qna/domain/Question.java @@ -54,34 +54,37 @@ public boolean isOwner(NsUser loginUser) { } public boolean isDeleted() { - return deleted; + return getDeleted(); } private void validateOwner(NsUser loginUser) throws CannotDeleteException { if (!this.isOwner(loginUser)) { throw new CannotDeleteException("์งˆ๋ฌธ์„ ์‚ญ์ œํ•  ๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค."); } + updateDeleted(); } public void delete(NsUser loginUser) throws CannotDeleteException { validateOwner(loginUser); - updateDeleted(); answers.validateAnswerOwner(loginUser); } public List toDeleteHistories(){ List deleteHistories = new ArrayList<>(); deleteHistories.add(new DeleteHistory(ContentType.QUESTION, this.id, this.writer, LocalDateTime.now())); - addDeleteAnswerHistory(deleteHistories); + + List answerDeleteHistories = addDeleteAnswerHistory(); + deleteHistories.addAll(answerDeleteHistories); + return deleteHistories; } - private void addDeleteAnswerHistory(List deleteHistories) { - this.answers.addDeleteAnswerHistory(deleteHistories); + private List addDeleteAnswerHistory() { + return this.answers.addDeleteAnswerHistory(); } private void updateDeleted() { - this.deleted = true; + deleted(); } @Override diff --git a/src/test/java/nextstep/qna/domain/QuestionTest.java b/src/test/java/nextstep/qna/domain/QuestionTest.java index 85df638873..894b837c39 100644 --- a/src/test/java/nextstep/qna/domain/QuestionTest.java +++ b/src/test/java/nextstep/qna/domain/QuestionTest.java @@ -22,6 +22,6 @@ public class QuestionTest { @Test void ์งˆ๋ฌธ_์‚ญ์ œ() throws CannotDeleteException { Q1.delete(Q1.getWriter()); - assertThat(Q1.deleted).isTrue(); + assertThat(Q1.isDeleted()).isTrue(); } } From 22a45a90a56dfbf37b0f96b3e09bf84e2f0f515b Mon Sep 17 00:00:00 2001 From: CHANHAN <130114269+chanani@users.noreply.github.com> Date: Thu, 27 Nov 2025 10:11:45 +0900 Subject: [PATCH 15/16] =?UTF-8?q?refactor=20:=20BaseModel=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EB=AA=85=20=EB=B3=80=EA=B2=BD=20##=20AI?= =?UTF-8?q?=EC=9D=98=20=EC=B6=94=EC=B2=9C=EC=9D=84=20=EB=B0=9B=EC=95=84=20?= =?UTF-8?q?=EC=A0=81=ED=95=A9=ED=95=9C=20=EC=9D=B4=EB=A6=84=EC=9D=84=20?= =?UTF-8?q?=EC=84=A0=ED=83=9D=ED=96=88=EC=8A=B5=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### ์ถ”์ฒœ ํด๋ž˜์Šค๋ช… 1. DeletableModel 2. SoftDeletableModel 3. AuditableModel ํ•ด๋‹น ํด๋ž˜์Šค๋Š” soft delete ์ •์ฑ…์„ ๋”ฐ๋ฅด๊ธฐ ๋•Œ๋ฌธ์— 2๋ฒˆ์˜ SoftDeletableModel๋กœ ์„ ํƒ --- src/main/java/nextstep/qna/domain/Answer.java | 2 +- src/main/java/nextstep/qna/domain/Question.java | 2 +- .../qna/domain/{BaseModel.java => SoftDeletableModel.java} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename src/main/java/nextstep/qna/domain/{BaseModel.java => SoftDeletableModel.java} (88%) diff --git a/src/main/java/nextstep/qna/domain/Answer.java b/src/main/java/nextstep/qna/domain/Answer.java index 5c0ad1639c..5f3267faf9 100644 --- a/src/main/java/nextstep/qna/domain/Answer.java +++ b/src/main/java/nextstep/qna/domain/Answer.java @@ -5,7 +5,7 @@ import nextstep.qna.UnAuthorizedException; import nextstep.users.domain.NsUser; -public class Answer extends BaseModel { +public class Answer extends SoftDeletableModel { private Long id; private NsUser writer; diff --git a/src/main/java/nextstep/qna/domain/Question.java b/src/main/java/nextstep/qna/domain/Question.java index ea8f41227a..c32e0e572d 100644 --- a/src/main/java/nextstep/qna/domain/Question.java +++ b/src/main/java/nextstep/qna/domain/Question.java @@ -7,7 +7,7 @@ import java.util.ArrayList; import java.util.List; -public class Question extends BaseModel { +public class Question extends SoftDeletableModel { private Long id; private Title title; diff --git a/src/main/java/nextstep/qna/domain/BaseModel.java b/src/main/java/nextstep/qna/domain/SoftDeletableModel.java similarity index 88% rename from src/main/java/nextstep/qna/domain/BaseModel.java rename to src/main/java/nextstep/qna/domain/SoftDeletableModel.java index 59fbbba9db..59d81c02ba 100644 --- a/src/main/java/nextstep/qna/domain/BaseModel.java +++ b/src/main/java/nextstep/qna/domain/SoftDeletableModel.java @@ -2,7 +2,7 @@ import java.time.LocalDateTime; -public abstract class BaseModel { +public abstract class SoftDeletableModel { private LocalDateTime createdDate = LocalDateTime.now(); From aa75be952dc86e95787971ae857ce46c102c1b0c Mon Sep 17 00:00:00 2001 From: CHANHAN <130114269+chanani@users.noreply.github.com> Date: Thu, 27 Nov 2025 10:46:34 +0900 Subject: [PATCH 16/16] =?UTF-8?q?refactor=20:=20Title,=20Contents=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=A0=9C=EA=B1=B0=20=ED=9B=84=20?= =?UTF-8?q?=EA=B3=B5=EC=9A=A9=EC=9C=BC=EB=A1=9C=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=A0=20QuestionBody=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/nextstep/qna/domain/Answer.java | 8 ++++---- src/main/java/nextstep/qna/domain/Question.java | 8 ++++---- .../qna/domain/{Contents.java => QuestionBody.java} | 4 ++-- src/main/java/nextstep/qna/domain/Title.java | 10 ---------- 4 files changed, 10 insertions(+), 20 deletions(-) rename src/main/java/nextstep/qna/domain/{Contents.java => QuestionBody.java} (58%) delete mode 100644 src/main/java/nextstep/qna/domain/Title.java diff --git a/src/main/java/nextstep/qna/domain/Answer.java b/src/main/java/nextstep/qna/domain/Answer.java index 5f3267faf9..e6d1da5bc1 100644 --- a/src/main/java/nextstep/qna/domain/Answer.java +++ b/src/main/java/nextstep/qna/domain/Answer.java @@ -12,20 +12,20 @@ public class Answer extends SoftDeletableModel { private Question question; - private Contents contents; + private QuestionBody contents; public Answer() { } public Answer(NsUser writer, Question question, String contents) { - this(null, writer, question, new Contents(contents)); + this(null, writer, question, new QuestionBody(contents)); } public Answer(Long id, NsUser writer, Question question, String contents) { - this(id, writer, question, new Contents(contents)); + this(id, writer, question, new QuestionBody(contents)); } - public Answer(Long id, NsUser writer, Question question, Contents contents) { + public Answer(Long id, NsUser writer, Question question, QuestionBody contents) { this.id = id; if (writer == null) { throw new UnAuthorizedException(); diff --git a/src/main/java/nextstep/qna/domain/Question.java b/src/main/java/nextstep/qna/domain/Question.java index c32e0e572d..cc397a565b 100644 --- a/src/main/java/nextstep/qna/domain/Question.java +++ b/src/main/java/nextstep/qna/domain/Question.java @@ -10,9 +10,9 @@ public class Question extends SoftDeletableModel { private Long id; - private Title title; + private QuestionBody title; - private Contents contents; + private QuestionBody contents; private NsUser writer; @@ -26,10 +26,10 @@ public Question(NsUser writer, String title, String contents) { } public Question(Long id, NsUser writer, String title, String contents) { - this(id, writer, new Title(title), new Contents(contents)); + this(id, writer, new QuestionBody(title), new QuestionBody(contents)); } - public Question(Long id, NsUser writer, Title title, Contents contents) { + public Question(Long id, NsUser writer, QuestionBody title, QuestionBody contents) { this.id = id; this.writer = writer; this.title = title; diff --git a/src/main/java/nextstep/qna/domain/Contents.java b/src/main/java/nextstep/qna/domain/QuestionBody.java similarity index 58% rename from src/main/java/nextstep/qna/domain/Contents.java rename to src/main/java/nextstep/qna/domain/QuestionBody.java index ff4993cdce..b6dbe7946b 100644 --- a/src/main/java/nextstep/qna/domain/Contents.java +++ b/src/main/java/nextstep/qna/domain/QuestionBody.java @@ -1,10 +1,10 @@ package nextstep.qna.domain; -public class Contents { +public class QuestionBody { private String value; - public Contents(String value) { + public QuestionBody(String value) { this.value = value; } } diff --git a/src/main/java/nextstep/qna/domain/Title.java b/src/main/java/nextstep/qna/domain/Title.java deleted file mode 100644 index 448dcb4550..0000000000 --- a/src/main/java/nextstep/qna/domain/Title.java +++ /dev/null @@ -1,10 +0,0 @@ -package nextstep.qna.domain; - -public class Title { - - private String value; - - public Title(String value) { - this.value = value; - } -}