Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
12 commits
Select commit Hold shift + click to select a range
c4960b6
docs : ๊ธฐ๋Šฅ ์š”๊ตฌ์‚ฌํ•ญ ๋ฌธ์„œ ์ž‘์„ฑ
chanani Nov 25, 2025
a117751
docs : ๋‚˜์˜ ํ•™์Šต ๋ชฉํ‘œ, PR์ „ ํ™•์ธํ•ด์•ผํ•  ๋ชฉ๋ก ์ž‘์„ฑ(ํ˜ธ์„ฑ๋‹˜์ด ์ž‘์„ฑํ•œ ๋‚ด์šฉ์— ๊ฐ๋ช… ๋ฐ›์•„ ์ €๋„ ๊ด€๋ฆฌํ•˜๋ ค๊ณ ํ•ฉ๋‹ˆ๋‹ค.)
chanani Nov 25, 2025
3cdb2ed
refactor : Question ๊ฐ์ฒด์— ์งˆ๋ฌธ ์‚ญ์ œ ๊ถŒํ•œ ์ฒดํฌ ๋ฉ”์„œ๋“œ ์ƒ์„ฑ ๋ฐ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ, Answer ๊ฐ์ฒด์— ์‚ญ์ œโ€ฆ
chanani Nov 25, 2025
9c9d031
refactor : Question ๊ฐ์ฒด์˜ ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜(answer) ํ™œ์šฉํ•ด ์ง์ ‘ Answer ๊ฐ์ฒด์˜ validateAnsโ€ฆ
chanani Nov 25, 2025
625a895
refactor : ์งˆ๋ฌธ, ๋‹ต๋ณ€ ์‚ญ์ œ ๋กœ์ง Question ๊ฐ์ฒด๋กœ ์ด๋™(Deleted ๊ฐ’์„ ๋ณ€๊ฒฝํ•˜๋Š” ๋กœ์ง์ด ํฌํ•จ๋˜์–ด ์žˆ์–ด์„œ โ€ฆ
chanani Nov 25, 2025
188c9d7
refactor : Question ํด๋ž˜์Šค์˜ List<Answer> ๋ณ€์ˆ˜ ํฌ์žฅ
chanani Nov 25, 2025
8312ece
docs : ํ—ท๊ฐˆ๋ฆฌ๋Š” ๋‚ด์šฉ Todo ์ถ”๊ฐ€
chanani Nov 26, 2025
f1b3547
refactor : ๊ณต๋™์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” createdDate, updatedDate, delted๋ฅผ BaseModel๋กœ ๋ถ„๋ฆฌ
chanani Nov 26, 2025
54e1f6d
refactor : title, contents ๊ฐ์ฒด ํฌ์žฅ
chanani Nov 26, 2025
c4db9bd
refactor : delete() ๋ฉ”์„œ๋“œ ํŒŒ๋ผ๋ฏธํ„ฐ ์ œ๊ฑฐ ๋ฐ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ˆ˜์ •
chanani Nov 26, 2025
400b772
refactor : ๊ฒ€์ฆํ•˜๋Š” ๋กœ์ง๊ณผ ์ƒํƒœ ๋ณ€๊ฒฝํ•˜๋Š” ๋กœ์ง์„ ํ•จ๊ป˜ ๊ตฌํ˜„,
chanani Nov 26, 2025
73effd2
feat : Answers ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ƒ์„ฑ
chanani Nov 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# ํ•™์Šต ๊ด€๋ฆฌ ์‹œ์Šคํ…œ(Learning Management System)

## ๋‹จ๊ณ„๋ณ„ ๋ฌธ์„œ
- [๐Ÿš€ 1๋‹จ๊ณ„ - ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ ๋ฆฌํŒฉํ„ฐ๋ง](./docs/01-refactoring.md)

## ์ง„ํ–‰ ๋ฐฉ๋ฒ•
* ํ•™์Šต ๊ด€๋ฆฌ ์‹œ์Šคํ…œ์˜ ์ˆ˜๊ฐ•์‹ ์ฒญ ์š”๊ตฌ์‚ฌํ•ญ์„ ํŒŒ์•…ํ•œ๋‹ค.
* ์š”๊ตฌ์‚ฌํ•ญ์— ๋Œ€ํ•œ ๊ตฌํ˜„์„ ์™„๋ฃŒํ•œ ํ›„ ์ž์‹ ์˜ github ์•„์ด๋””์— ํ•ด๋‹นํ•˜๋Š” ๋ธŒ๋žœ์น˜์— Pull Request(์ดํ•˜ PR)๋ฅผ ํ†ตํ•ด ์ฝ”๋“œ ๋ฆฌ๋ทฐ ์š”์ฒญ์„ ํ•œ๋‹ค.
Expand Down
37 changes: 37 additions & 0 deletions docs/01-refactoring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# ๐Ÿš€ 1๋‹จ๊ณ„ - ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ ๋ฆฌํŒฉํ„ฐ๋ง
***

## ์ฝ”๋“œ ๋ฆฌ๋ทฐ
> PR ๋งํฌ :
## ๋‚˜์˜ ํ•™์Šต ๋ชฉํ‘œ
Copy link
Contributor

Choose a reason for hiding this comment

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

๐Ÿ‘


### 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์˜ ๋ชจ๋“  ํ…Œ์ŠคํŠธ๋Š” ํ†ต๊ณผํ•ด์•ผ ํ•œ๋‹ค.
12 changes: 12 additions & 0 deletions docs/check-list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# โœ”๏ธ PR ์ „ ํ™•์ธํ•ด์•ผ๋  ๋ชฉ๋ก
Copy link
Contributor

Choose a reason for hiding this comment

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

๐Ÿ‘

***

- ๊ฐ์ฒด์ง€ํ–ฅ ์ƒํ™œ์ฒด์กฐ ์›์น™์„ ์ค€์ˆ˜ํ•˜์˜€๋Š”๊ฐ€ ?
- TDD ์‚ฌ์ดํด๋กœ ๊ตฌํ˜„ํ•˜์˜€๋Š”๊ฐ€ ?
- TDD ์‚ฌ์ดํด ๋‹จ์œ„๋กœ ์ปค๋ฐ‹ํ•˜์˜€๋Š”๊ฐ€ ?
- ๊ฐ์ฒด์—๊ฒŒ ์ƒํƒœ๋ฅผ ๋…ธ์ถœ์‹œํ‚ค์ง€ ์•Š๊ณ  ์ฑ…์ž„์„ ๋งก๊ฒผ๋Š”๊ฐ€ ?
- ํ…Œ์Šฝ์œผ๋Š” ๊ฐ์ฒด์˜ ์ฑ…์ž„๊ณผ ๊ฒฐ๊ณผ๋งŒ ๊ฒ€์ฆํ–ˆ๋Š”๊ฐ€ ?
- ๋ถˆ๋ณ€์„ฑ์„ ์ตœ๋Œ€ํ•œ ์œ ์ง€ํ–ˆ๋Š”๊ฐ€ ?
- ๋„๋ฉ”์ธ ์šฉ์–ด๋กœ ๋„ค์ด๋ฐ ํ–ˆ๋Š”๊ฐ€ ?
- ํ˜‘๋ ฅ ๊ตฌ์กฐ๊ฐ€ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์ฝํžˆ๋Š”๊ฐ€ ?
- ๊ฐ™์€ ํ”ผ๋“œ๋ฐฑ์„ ๋ฐ˜๋ณตํ•˜์ง€๋Š” ์•Š์•˜๋Š”๊ฐ€ ?
36 changes: 20 additions & 16 deletions src/main/java/nextstep/qna/domain/Answer.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
package nextstep.qna.domain;

import nextstep.qna.CannotDeleteException;
import nextstep.qna.NotFoundException;
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;

private Question question;

private String contents;

private boolean deleted = false;

private LocalDateTime createdDate = LocalDateTime.now();

private LocalDateTime updatedDate;
private Contents contents;

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) {
if (writer == null) {
throw new UnAuthorizedException();
}

if(question == null) {
if (question == null) {
throw new NotFoundException();
}

Expand All @@ -52,6 +49,10 @@ public Answer setDeleted(boolean deleted) {
return this;
}

public void updateDeleted() {
Copy link
Contributor

Choose a reason for hiding this comment

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

์‚ญ์ œ ์ƒํƒœ ๋ณ€๊ฒฝ์— ๋”ฐ๋ฅธ ๊ฒ€์ฆ์„ ํ•˜๋Š” ๊ฒƒ์„ ๊ณ ๋ คํ–ˆ์„ ๋•Œ private์œผ๋กœ ๊ตฌํ˜„ํ•ด์•ผ ์•ˆ์ „ํ•˜์ง€ ์•Š์„๊นŒ?

this.deleted = true;
}

public boolean isDeleted() {
return deleted;
}
Expand All @@ -64,14 +65,17 @@ public NsUser getWriter() {
return writer;
}

public String getContents() {
return contents;
}

public void toQuestion(Question question) {
this.question = question;
}

public void validateAnswerOwner(NsUser loginUser) throws CannotDeleteException {
if (!this.isOwner(loginUser)) {
throw new CannotDeleteException("๋‹ค๋ฅธ ์‚ฌ๋žŒ์ด ์“ด ๋‹ต๋ณ€์ด ์žˆ์–ด ์‚ญ์ œํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

ํ˜„์žฌ๋Š” valid์™€ updateDeleted๊ฐ€ ๋ถ„๋ฆฌ๋˜์–ด ๊ตฌํ˜„๋˜์–ด ์žˆ์Œ.
์ด ๋‘˜์„ ํ•˜๋‚˜๋กœ ๊ตฌํ˜„ํ•˜๋Š” ์•„๋ž˜์™€ ๋น„๊ตํ–ˆ์„ ๋•Œ ์–ด๋А ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ์ด ๋” ์ข‹์„๊นŒ?

Suggested change
public void delete(NsUser loginUser) throws CannotDeleteException {
// ์œ ํšจ์„ฑ ์ฒดํฌ์™€ ์‚ญ์ œ ์ƒํƒœ๋กœ ๋ณ€๊ฒฝ
}

Copy link
Contributor

Choose a reason for hiding this comment

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

์ด ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜ํ–ˆ๋Š”์ง€ ํ™•์ธ ํ•„์š”

@Override
public String toString() {
return "Answer [id=" + getId() + ", writer=" + writer + ", contents=" + contents + "]";
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/nextstep/qna/domain/Answers.java
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
answer.updateDeleted();
}
}

public void addDeleteAnswerHistory(List<DeleteHistory> deleteHistories) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public void addDeleteAnswerHistory(List<DeleteHistory> deleteHistories) {
public List<DeleteHistory> toDeleteAnswerHistories() {
List<DeleteHistory> deleteHistories = new ArrayList<>();

๊ฐœ์ธ์ ์œผ๋กœ List ์ฝœ๋ ‰์…˜์„ ์ธ์ž๋กœ ์ „๋‹ฌํ•ด ์ €์žฅํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ์œ„์™€ ๊ฐ™์ด ํ•ด๋‹น ๋ฉ”์„œ๋“œ์—์„œ ์ง์ ‘ ์ƒ์„ฑํ•ด ๋ฐ˜ํ™˜ํ•˜๋Š” ๊ฒƒ์ด ๋‹ค๋ฅธ ๊ฐ์ฒด์™€์˜ ์˜์กด ๊ด€๊ณ„๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์„ ํ˜ธํ•˜๋Š” ๋ฐฉ๋ฒ•์ž„

for (Answer answer : this.answers) {
deleteHistories.add(new DeleteHistory(ContentType.ANSWER, answer.getId(), answer.getWriter(), LocalDateTime.now()));
}
}
}
12 changes: 12 additions & 0 deletions src/main/java/nextstep/qna/domain/BaseModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package nextstep.qna.domain;

import java.time.LocalDateTime;

public abstract class BaseModel {
Copy link
Contributor

Choose a reason for hiding this comment

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

๐Ÿ‘
๋‹จ, ํ”„๋กœ์ ํŠธ์— ๋ชจ๋“  ์ปจํ…์ธ ๋Š” ์„ฑ๊ฒฉ์˜ ๋ฐ์ดํ„ฐ๋Š” soft delete ์ •์ฑ…์„ ๋”ฐ๋ฅธ๋‹ค์™€ ๊ฐ™์€ ๊ทœ์น™์ด ์žˆ์„ ๊ฒฝ์šฐ deleted ์ƒํƒœ๋ฅผ ํฌํ•จํ•˜๋Š” ๊ฒƒ์ด ์ถ”์ƒํ™” ์ธก๋ฉด์—์„œ ๋งž์Œ.
์ด๋ ‡๊ฒŒ ๋  ๊ฒฝ์šฐ ์ด BaseModel์€ ์ด ๊ทœ์น™์„ ๋”ฐ๋ฅด์ง€ ์•Š๋Š” Model์€ ์ƒ์†ํ•  ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ์ฒด์˜ ์ด๋ฆ„์„ ๋” ๊ตฌ์ฒด์ ์œผ๋กœ ์ž‘์„ฑํ•  ๊ฒƒ์„ ์ถ”์ฒœ
AI์—๊ฒŒ ํ”„๋กœ์ ํŠธ์˜ ์ •์ฑ…์„ ์„ค๋ช…ํ•˜๊ณ  ๋” ์ ํ•ฉํ•œ ์ด๋ฆ„์„ ์ถ”์ฒœ ๋ฐ›์•„๋ณธ๋‹ค.


public LocalDateTime createdDate = LocalDateTime.now();

public LocalDateTime updatedDate;

public boolean deleted = false;
Comment on lines +7 to +11
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public LocalDateTime createdDate = LocalDateTime.now();
public LocalDateTime updatedDate;
public boolean deleted = false;
private LocalDateTime createdDate = LocalDateTime.now();
private LocalDateTime updatedDate;
private boolean deleted = false;

๋ชจ๋“  ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜๋Š” ๊ฐ€๋Šฅํ•˜๋ฉด private์œผ๋กœ ๊ตฌํ˜„

Comment on lines +7 to +11
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public LocalDateTime createdDate = LocalDateTime.now();
public LocalDateTime updatedDate;
public boolean deleted = false;
private boolean deleted = false;

๊ทธ๋Ÿผ ์ƒํƒœ ๊ฐ’ ๋ณ€๊ฒฝ์€ ์–ด๋–ป๊ฒŒ ํ•˜๋‚˜?

    protected void deleted() {
        this.deleted = true;
    }

์•„๋ž˜์™€ ๊ฐ™์ด protected ๋ฉ”์„œ๋“œ๋ฅผ ์ œ๊ณตํ•˜๊ณ  ์ž์‹ ํด๋ž˜์Šค์—์„œ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•œ๋‹ค.

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

public class Contents {
Copy link
Contributor

Choose a reason for hiding this comment

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

์ด ๊ฐ์ฒด๋Š” ๊ฐ’์„ ํฌ์žฅํ•˜๋Š” ๊ฒƒ ์™ธ์— ์•„๋ฌด ๋กœ์ง๋„ ์—†๋Š”๋ฐ ํฌ์žฅํ•˜๋Š” ๊ฒƒ์ด ์˜๋ฏธ์žˆ์„๊นŒ?
Title ๋™์ผ
๋‹จ, title๊ณผ contents๋ฅผ ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜๋ฅผ ๊ฐ€์ง€๋Š” QuestionBody์™€ ๊ฐ™์€ ๊ฐ์ฒด๋ฅผ ๋ถ„๋ฆฌํ•œ๋‹ค๋ฉด ์˜๋ฏธ์žˆ์„๊นŒ?


private String value;

public Contents(String value) {
this.value = value;
}
}
69 changes: 39 additions & 30 deletions src/main/java/nextstep/qna/domain/Question.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
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 Question {
public class Question extends BaseModel {
private Long id;

private String title;
private Title title;

private String contents;
private Contents contents;

private NsUser writer;

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

private boolean deleted = false;

private LocalDateTime createdDate = LocalDateTime.now();

private LocalDateTime updatedDate;
private Answers answers = new Answers();

public Question() {
}
Expand All @@ -31,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;
Expand All @@ -41,31 +40,13 @@ 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;
}

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

public boolean isOwner(NsUser loginUser) {
Expand All @@ -82,11 +63,39 @@ public boolean isDeleted() {
}

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

private void validateOwner(NsUser loginUser) throws CannotDeleteException {
if (!this.isOwner(loginUser)) {
throw new CannotDeleteException("์งˆ๋ฌธ์„ ์‚ญ์ œํ•  ๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค.");
}
}

public void delete(NsUser loginUser) throws CannotDeleteException {
validateOwner(loginUser);
updateDeleted();
answers.validateAnswerOwner(loginUser);
}

public List<DeleteHistory> toDeleteHistories(){
List<DeleteHistory> deleteHistories = new ArrayList<>();
deleteHistories.add(new DeleteHistory(ContentType.QUESTION, this.id, this.writer, LocalDateTime.now()));
addDeleteAnswerHistory(deleteHistories);
return deleteHistories;
}

Copy link
Contributor

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 ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฉ”์„œ๋“œ ๋‘ ๊ฐœ๋กœ ๋ถ„๋ฆฌํ•˜๋Š” ๊ฒƒ ์ค‘ ์–ด๋А ์ ‘๊ทผ ๋ฐฉ์‹์ด ์ข‹์„๊นŒ?

private void addDeleteAnswerHistory(List<DeleteHistory> deleteHistories) {
this.answers.addDeleteAnswerHistory(deleteHistories);
}

private void updateDeleted() {
this.deleted = true;
}

@Override
public String toString() {
return "Question [id=" + getId() + ", title=" + title + ", contents=" + contents + ", writer=" + writer + "]";
}

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

public class Title {

private String value;

public Title(String value) {
this.value = value;
}
}
21 changes: 2 additions & 19 deletions src/main/java/nextstep/qna/service/QnAService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -26,24 +24,9 @@ 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.delete(loginUser);

List<Answer> answers = question.getAnswers();
for (Answer answer : answers) {
if (!answer.isOwner(loginUser)) {
throw new CannotDeleteException("๋‹ค๋ฅธ ์‚ฌ๋žŒ์ด ์“ด ๋‹ต๋ณ€์ด ์žˆ์–ด ์‚ญ์ œํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}
}

List<DeleteHistory> 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<DeleteHistory> deleteHistories = question.toDeleteHistories();
deleteHistoryService.saveAll(deleteHistories);
}
}
Loading