-
Notifications
You must be signed in to change notification settings - Fork 308
step1 - 레거시 코드 리팩토링 리뷰요청 드립니다. #812
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4a9ebbe
feat: Answers 일급 컬렉션 적용
qwer920414-ctrl d7b11ba
feat: Question - validateOwner()
qwer920414-ctrl dc2cdae
feat: Question delete() & validateOwner TestCode
qwer920414-ctrl d774fcc
refactor: Question 캡슐화
qwer920414-ctrl 50e0590
refactor: 구조 개선
qwer920414-ctrl 5f030fb
refactor: Answer 클래스 수정(delete 메소드 역할 분리)
qwer920414-ctrl cc4d61d
refactor: Answers 클래스 개선(테스트코드 AnswerTest로 확인 가능)
qwer920414-ctrl db336be
test: Answer test 추가
qwer920414-ctrl 78f1f05
refactor: Question 클래스 수정
qwer920414-ctrl a923491
refactor: Question 클래스 객체 분리
qwer920414-ctrl bac8b20
refactor: 공통 Delete 전용 BaseEntity 생성
qwer920414-ctrl eca6a37
refactor: Answer 클래스에도 공통 delete BaseEntity 적용
qwer920414-ctrl c8722dd
style: 불필요 로직 삭제
qwer920414-ctrl ea0d50a
refactor: DeleteHistory 정적 팩토리 메소드 추가 - 적용
qwer920414-ctrl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package nextstep.qna.domain; | ||
|
|
||
| import nextstep.qna.CannotDeleteException; | ||
| import nextstep.users.domain.NsUser; | ||
|
|
||
| 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; | ||
|
|
||
| public Answers() { | ||
| this(new ArrayList<>()); | ||
| } | ||
|
|
||
| public Answers(List<Answer> answers) { | ||
| this.answers = new ArrayList<>(answers); | ||
| } | ||
|
|
||
| public void add(Answer answer) { | ||
| answers.add(answer); | ||
| } | ||
|
|
||
| public void deleteAll(NsUser loginUser) throws CannotDeleteException { | ||
| for (Answer answer : answers) { | ||
| answer.delete(loginUser); | ||
| } | ||
| } | ||
|
|
||
| public List<DeleteHistory> toDeleteHistories() { | ||
| List<DeleteHistory> deleteHistories = new ArrayList<>(); | ||
| for (Answer answer : answers) { | ||
| deleteHistories.add(answer.deleteHistory()); | ||
| } | ||
| return deleteHistories; | ||
| } | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
src/main/java/nextstep/qna/domain/DeletableBaseEntity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package nextstep.qna.domain; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public abstract class DeletableBaseEntity { | ||
|
|
||
| private Long id; | ||
| private boolean deleted = false; | ||
|
|
||
| private LocalDateTime createdDate = LocalDateTime.now(); | ||
|
|
||
| private LocalDateTime updatedDate; | ||
|
|
||
| protected DeletableBaseEntity() { | ||
| } | ||
|
|
||
| public DeletableBaseEntity(Long id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| protected void delete() { | ||
|
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. 👍 |
||
| this.deleted = true; | ||
| } | ||
|
|
||
| public boolean isDeleted() { | ||
| return deleted; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package nextstep.qna.domain; | ||
|
|
||
| public class QuestionContent { | ||
| private String title; | ||
| private String contents; | ||
|
|
||
| public QuestionContent(String title, String contents) { | ||
| this.title = title; | ||
| this.contents = contents; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,43 @@ | ||
| package nextstep.qna.domain; | ||
|
|
||
| import nextstep.qna.CannotDeleteException; | ||
| import nextstep.users.domain.NsUser; | ||
| import nextstep.users.domain.NsUserTest; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
|
||
| 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 delete_다른사람이_쓴_답변이_있으면_삭제불가() { | ||
| NsUser user = NsUserTest.JAVAJIGI; | ||
| Answer answer = AnswerTest.A2; | ||
| assertThatThrownBy(() -> answer.delete(user)) | ||
| .isInstanceOf(CannotDeleteException.class); | ||
| } | ||
|
|
||
| @Test | ||
| void delete_성공() throws CannotDeleteException { | ||
| NsUser user = NsUserTest.JAVAJIGI; | ||
| Answer answer = AnswerTest.A1; | ||
|
|
||
| answer.delete(user); | ||
|
|
||
| assertThat(answer.isDeleted()).isTrue(); | ||
| } | ||
|
|
||
| @Test | ||
| void deleteHistory_생성() { | ||
| Answer answer = AnswerTest.A1; | ||
|
|
||
| DeleteHistory history = answer.deleteHistory(); | ||
|
|
||
| assertThat(history).isEqualTo(DeleteHistory.from(ContentType.ANSWER, answer.getId(), answer.getWriter(), LocalDateTime.now())); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
👍