Repository navigation
Step5 #141
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
Step5 #141
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,107 @@ | ||
| package codesquad.domain; | ||
|
|
||
| import codesquad.CannotDeleteException; | ||
| import codesquad.UnAuthorizedException; | ||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| import org.slf4j.Logger; | ||
| import support.domain.AbstractEntity; | ||
|
|
||
| import javax.persistence.*; | ||
| import javax.validation.constraints.Size; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import static org.slf4j.LoggerFactory.getLogger; | ||
|
|
||
| @Entity | ||
| public class Answer extends AbstractEntity { | ||
| private static final Logger log = getLogger(Answer.class); | ||
|
|
||
| @Size(min = 2, max = 500) | ||
| @Column(nullable = false, length = 500) | ||
| private String comment; | ||
|
|
||
| @ManyToOne | ||
| @JoinColumn(foreignKey = @ForeignKey(name = "fk_comment_writer")) | ||
| private User writer; | ||
|
|
||
| @ManyToOne | ||
| @JoinColumn(foreignKey = @ForeignKey(name = "fk_comment_issue")) | ||
| private Issue issue; | ||
|
|
||
| private boolean deleted = false; | ||
|
|
||
| public Answer() { | ||
| } | ||
|
|
||
| public Answer(long id, @Size(min = 2, max = 500) String comment, User writer, Issue issue, boolean deleted) { | ||
| super(id); | ||
| this.comment = comment; | ||
| this.writer = writer; | ||
| this.issue = issue; | ||
| this.deleted = deleted; | ||
| } | ||
|
|
||
| public Answer(User loginUser, Issue issue, String newComment) { | ||
| this.writer = loginUser; | ||
| this.issue = issue; | ||
| this.comment = newComment; | ||
| } | ||
|
|
||
| public String getComment() { | ||
| return comment; | ||
| } | ||
|
|
||
| public void setComment(String comment) { | ||
| this.comment = comment; | ||
| } | ||
|
|
||
| public User getWriter() { | ||
| return writer; | ||
| } | ||
|
|
||
| public void setWriter(User writer) { | ||
| this.writer = writer; | ||
| } | ||
|
|
||
| public Issue getIssue() { | ||
| return issue; | ||
| } | ||
|
|
||
| public void setIssue(Issue issue) { | ||
| this.issue = issue; | ||
| } | ||
|
|
||
| public boolean isDeleted() { | ||
| return deleted; | ||
| } | ||
|
|
||
| public void setDeleted(boolean deleted) { | ||
| this.deleted = deleted; | ||
| } | ||
|
|
||
| public void update(String update, User loginUser) { | ||
| if (!this.writer.equals(loginUser)) { | ||
| throw new UnAuthorizedException(); | ||
| } | ||
| log.debug("update domain : {}", update); | ||
| this.comment = update; | ||
| } | ||
|
|
||
| public DeleteHistory delete(User loginUser) { | ||
| if (!this.writer.equals(loginUser)) { | ||
| throw new CannotDeleteException("다른사람의 답글을 지울수 없습니다."); | ||
| } | ||
| this.deleted = true; | ||
| return new DeleteHistory(ContentType.ANSWER, getId(), loginUser); | ||
| } | ||
|
|
||
| public static List<DeleteHistory> deleteAnswers(List<Answer> answers, User loginUser) { | ||
| List<DeleteHistory> answersInfo = new ArrayList<>(); | ||
| for (Answer answer : answers) { | ||
| answersInfo.add(answer.delete(loginUser)); | ||
| } | ||
| return answersInfo; | ||
| } | ||
| } |
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,12 @@ | ||
| package codesquad.domain; | ||
|
|
||
| import org.springframework.data.repository.CrudRepository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface AnswerRepository extends CrudRepository<Answer, Long> { | ||
|
|
||
| Iterable<Answer> findByDeleted(boolean b); | ||
|
|
||
| List<Answer> findByIssueId(long id); | ||
| } |
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,5 +1,5 @@ | ||
| package codesquad.domain; | ||
|
|
||
| public enum ContentType { | ||
| ISSUE | ||
| ISSUE, ANSWER | ||
| } |
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,19 @@ | ||
| package codesquad.domain; | ||
|
|
||
| import support.domain.AbstractEntity; | ||
|
|
||
| import javax.persistence.Entity; | ||
|
|
||
| @Entity | ||
| public class MileStoneOpen extends AbstractEntity { | ||
|
|
||
| private boolean open = false; | ||
|
|
||
| public boolean isOpen() { | ||
| return open; | ||
| } | ||
|
|
||
| public void setOpen(boolean open) { | ||
| this.open = open; | ||
| } | ||
| } |
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.
이 filter는 스프링 부트에 이미 설정되어 있으니 굳이 추가하지 않아도 됨