-
Notifications
You must be signed in to change notification settings - Fork 432
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
Step1: 리팩터링 #969
Open
hungryjayy
wants to merge
10
commits into
next-step:hungryjayy
Choose a base branch
from
hungryjayy:step1
base: hungryjayy
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Step1: 리팩터링 #969
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b3460ae
docs: Update readme
hungryjayy 9042937
test: Add question method
hungryjayy ee833e3
refactor: Extract validate method to question domain
hungryjayy d076b14
test: Add answer validate test
hungryjayy f717dca
refactor: Extract validate method to answer domain
hungryjayy e8103d4
test: Add question validate answer exists test
hungryjayy 9e9d5f9
refactor: Add validateAnswer method in question
hungryjayy 668ff96
refactor: Integrate validate method
hungryjayy ff8dca8
refactor: Delete history to firstclass collection
hungryjayy 20cff0d
docs: Update readme
hungryjayy 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 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 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 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,31 @@ | ||
package qna.domain; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class DeleteHistories { | ||
private List<DeleteHistory> deleteHistories = new ArrayList<>(); | ||
|
||
public DeleteHistories() { | ||
} | ||
|
||
public DeleteHistories(List<DeleteHistory> deleteHistories) { | ||
this.deleteHistories = deleteHistories; | ||
} | ||
|
||
public void add(long questionId, Question question) { | ||
question.setDeleted(true); | ||
LocalDateTime now = LocalDateTime.now(); | ||
deleteHistories.add(new DeleteHistory(ContentType.QUESTION, questionId, question.getWriter(), now)); | ||
|
||
for (Answer answer : question.getAnswers()) { | ||
answer.setDeleted(true); | ||
deleteHistories.add(new DeleteHistory(ContentType.ANSWER, answer.getId(), answer.getWriter(), now)); | ||
} | ||
} | ||
|
||
public List<DeleteHistory> getHistories() { | ||
return deleteHistories; | ||
} | ||
} |
This file contains 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 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 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,6 +1,21 @@ | ||
package qna.domain; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import qna.CannotDeleteException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
public class AnswerTest { | ||
public static final Answer A1 = new Answer(UserTest.JAVAJIGI, QuestionTest.Q1, "Answers Contents1"); | ||
public static final Answer A2 = new Answer(UserTest.SANJIGI, QuestionTest.Q1, "Answers Contents2"); | ||
|
||
@Test | ||
@DisplayName("다른 사람이 쓴 답변이 있는 경우 CannotDeleteException을 throw한다.") | ||
public void validate_다른_사람의_답변_있는_글() { | ||
assertThatThrownBy(() -> { | ||
A1.validateAnswerExists(UserTest.SANJIGI); | ||
}).isInstanceOf(CannotDeleteException.class) | ||
.hasMessageContaining("다른 사람이 쓴 답변이 있어 삭제할 수 없습니다."); | ||
} | ||
} |
This file contains 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,29 @@ | ||
package qna.domain; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static qna.domain.QuestionTest.Q1; | ||
|
||
class DeleteHistoriesTest { | ||
public static final DeleteHistory DELETE_HISTORY1 = new DeleteHistory(ContentType.QUESTION, 1L, Q1.getWriter(), | ||
LocalDateTime.now()); | ||
|
||
public static final DeleteHistories DELETE_HISTORIES1 = new DeleteHistories(List.of(DELETE_HISTORY1)); | ||
|
||
public static final DeleteHistories DELETE_HISTORIES2 = new DeleteHistories(); | ||
|
||
@Test | ||
@DisplayName("Delete 히스토리를 추가한다.") | ||
public void add_히스토리를_추가한다() { | ||
int questionId = 1; | ||
|
||
DELETE_HISTORIES2.add(questionId, Q1); | ||
|
||
assertThat(DELETE_HISTORIES2.getHistories()).isEqualTo(DELETE_HISTORIES1.getHistories()); | ||
} | ||
} |
This file contains 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,6 +1,34 @@ | ||
package qna.domain; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import qna.CannotDeleteException; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static qna.domain.AnswerTest.A2; | ||
|
||
public class QuestionTest { | ||
public static final Question Q1 = new Question("title1", "contents1").writeBy(UserTest.JAVAJIGI); | ||
public static final Question Q2 = new Question("title2", "contents2").writeBy(UserTest.SANJIGI); | ||
public static final Question Q3 = new Question("title1", "contents1", List.of(A2)).writeBy(UserTest.JAVAJIGI); | ||
|
||
@Test | ||
@DisplayName("다른 사람이 쓴 글의 경우 CannotDeleteException을 throw한다.") | ||
public void validate_다른_사람이_쓴_글() { | ||
assertThatThrownBy(() -> { | ||
Q1.validate(UserTest.SANJIGI); | ||
}).isInstanceOf(CannotDeleteException.class) | ||
.hasMessageContaining("질문을 삭제할 권한이 없습니다."); | ||
} | ||
|
||
@Test | ||
@DisplayName("다른 사람이 쓴 답변이 있는 경우 CannotDeleteException을 throw한다.") | ||
public void validate_다른_사람의_답변_있는_글() { | ||
assertThatThrownBy(() -> { | ||
Q3.validate(UserTest.JAVAJIGI); | ||
}).isInstanceOf(CannotDeleteException.class) | ||
.hasMessageContaining("다른 사람이 쓴 답변이 있어 삭제할 수 없습니다."); | ||
} | ||
} |
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.
DeleteHistory 내부에서 question 과 answer 을 다루기보다
anwser 과 question 이 DeleteHistory 를 리턴하는 구조가 더 자연스럽지 않을까요?