Skip to content

Commit

Permalink
Merge pull request #232 from woowacourse-teams/refactor/231-delete-ad…
Browse files Browse the repository at this point in the history
…dLike

#231 사용하지 않는 코드 삭제 및 응답 Location 오류 수정
  • Loading branch information
chomily authored Oct 13, 2020
2 parents b037a1a + 36d892b commit d639e21
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class LikeController {
public ResponseEntity<Void> likeArticle(@LoginMember Member member, @PathVariable Long articleId) {
ArticleLike articleLike = likeService.likeArticle(member, articleId);
return ResponseEntity
.created(URI.create("/article/" + articleId + "/likes/" + articleLike.getId()))
.created(URI.create("/articles/" + articleId + "/likes/" + articleLike.getId()))
.build();
}

Expand All @@ -35,7 +35,7 @@ public ResponseEntity<Void> unlikeArticle(@LoginMember Member member, @PathVaria
public ResponseEntity<Void> likeComment(@LoginMember Member member, @PathVariable Long articleId, @PathVariable Long commentId) {
CommentLike commentLike = likeService.likeComment(member, commentId);
return ResponseEntity
.created(URI.create("/likes/comment/" + commentId + "/comment_like" + commentLike.getId()))
.created(URI.create("/articles/" + articleId + "/comments/" + commentId + "/likes/" + commentLike.getId()))
.build();
}

Expand Down
15 changes: 0 additions & 15 deletions src/main/java/com/saebyeok/saebyeok/domain/Comment.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.saebyeok.saebyeok.domain;

import com.saebyeok.saebyeok.exception.DuplicateCommentLikeException;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -98,20 +97,6 @@ public void setParent(Comment parent) {
this.parent = parent;
}

public void addLike(CommentLike like) {
Objects.requireNonNull(like);

if (like.getComment() != this) {
// TODO: 2020/08/22 : 커스텀 Exception 생성해서 사용하기
throw new RuntimeException();
}

if (this.likes.contains(like)) {
throw new DuplicateCommentLikeException(like.getMember().getId(), like.getComment().getId());
}
this.likes.add(like);
}

@Override
public int compareTo(Comment other) {
Comment parentOfThis = (this.parent == null ? this : this.parent);
Expand Down
22 changes: 0 additions & 22 deletions src/test/java/com/saebyeok/saebyeok/domain/CommentTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.saebyeok.saebyeok.domain;

import com.saebyeok.saebyeok.exception.DuplicateCommentLikeException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -13,7 +12,6 @@
import java.util.stream.Collectors;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class CommentTest {
public static final String TEST_CONTENT = "새벽 좋아요";
Expand Down Expand Up @@ -47,26 +45,6 @@ void createCommentTest() {
assertThat(comment.getIsDeleted()).isFalse();
}

@DisplayName("예외 테스트: 해당 댓글에 대한 CommentLike가 아닌 CommentLike를 추가하면 예외가 발생한다")
@Test
void addInvalidLikeExceptionTest() {
CommentLike invalidCommentLike = new CommentLike(member, comment2);

assertThatThrownBy(() -> comment1.addLike(invalidCommentLike))
.isInstanceOf(RuntimeException.class);
}

@DisplayName("예외 테스트: 이미 존재하는 CommentLike를 추가하면 예외가 발생한다")
@Test
void addLikeExceptionTest() {
CommentLike commentLike = new CommentLike(member, comment1);
comment1.addLike(commentLike);

assertThatThrownBy(() -> comment1.addLike(commentLike))
.isInstanceOf(DuplicateCommentLikeException.class)
.hasMessage("이미 공감한 댓글에 추가 공감을 할 수 없습니다. MemberId: " + member.getId() + ", commentId: " + comment1.getId());
}

@DisplayName("특정 사용자가 해당 댓글을 공감했는지 여부를 확인할 수 있다")
@Test
void isLikedByTest() {
Expand Down

0 comments on commit d639e21

Please sign in to comment.