Skip to content

Commit

Permalink
feat: (#36) 자신이 작성한 글에는 투표하지 못하는 검증 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
aiaiaiai1 committed Jul 13, 2023
1 parent 06747f7 commit 52179ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,19 @@ private Member(

public Vote vote(final Post post, final Long postOptionId) {
PostOption postOption = post.findPostOptionById(postOptionId);
validateWriter(post);
return Vote.builder()
.member(this)
.postOption(postOption)
.build();
}

private void validateWriter(Post post) {
if (post.isWriter(this)) {
throw new IllegalArgumentException("자기자신은 투표할 수 없습니다.");
}
}

public void plusPoint(int point) {
this.point = this.point + point;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ public PostOption findPostOptionById(final Long PostOptionId) {
.orElseThrow(() -> new IllegalArgumentException("해당 게시글에서 존재하지 않는 선택지 입니다."));
}

public boolean isWriter(Member member) {
return this.member == member;
}

}

0 comments on commit 52179ba

Please sign in to comment.