-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #425 from boy0516/step1
- Loading branch information
Showing
9 changed files
with
130 additions
and
86 deletions.
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,36 @@ | ||
package nextstep.qna.domain; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.*; | ||
|
||
import nextstep.users.domain.NsUser; | ||
|
||
public class Answers { | ||
|
||
private List<Answer> answers; | ||
|
||
public Answers(List<Answer> answers) { | ||
this.answers = answers; | ||
} | ||
|
||
public void add(Answer answer) { | ||
answers.add(answer); | ||
} | ||
|
||
public boolean isContainOtherOwner(NsUser loginUser) { | ||
return answers.stream() | ||
.anyMatch(answer -> !answer.isOwner(loginUser)); | ||
} | ||
|
||
public void delete() { | ||
answers.forEach(answer -> answer.delete()); | ||
} | ||
|
||
public List<DeleteHistory> getDeleteHistory() { | ||
List<DeleteHistory> deleteHistories = new ArrayList<>(); | ||
for (Answer answer : answers) { | ||
deleteHistories.add(new DeleteHistory(ContentType.ANSWER, answer.getId(), answer.getWriter(), LocalDateTime.now())); | ||
} | ||
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
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,8 +1,19 @@ | ||
package nextstep.qna.domain; | ||
|
||
import nextstep.qna.CannotDeleteException; | ||
import nextstep.users.domain.NsUserTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
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 삭제_테스트() throws CannotDeleteException { | ||
A1.delete(); | ||
assertThat(A1.isDeleted()).isEqualTo(true); | ||
} | ||
} |
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,8 +1,19 @@ | ||
package nextstep.qna.domain; | ||
|
||
import nextstep.qna.CannotDeleteException; | ||
import nextstep.users.domain.NsUserTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
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 삭제_테스트() throws CannotDeleteException { | ||
Q1.deleteBy(NsUserTest.JAVAJIGI); | ||
assertThat(Q1.isDeleted()).isEqualTo(true); | ||
} | ||
} |
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