Skip to content

Commit

Permalink
feat(comment): 댓글 삭제 Api
Browse files Browse the repository at this point in the history
  • Loading branch information
Woongbin06 committed Jan 3, 2024
1 parent 1012587 commit 73bf592
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down Expand Up @@ -56,4 +57,11 @@ public List<CommentResponse> findByQnA(@PathVariable(name = "qna-id") Long qnAId
.map(comment -> CommentResponse.of(comment, comment.getWriter()))
.toList();
}

@ResponseStatus(HttpStatus.NO_CONTENT)
@DeleteMapping("/{comment-id}")
public void deleteComment(@PathVariable(name = "comment-id") Long commentId) {
User writer = userTempService.getUserId1();
commandCommentService.deleteComment(commentId, writer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.sickgyun.server.commnet.domain.Comment;
import com.sickgyun.server.commnet.service.implementation.CommentCreator;
import com.sickgyun.server.commnet.service.implementation.CommentDeleter;
import com.sickgyun.server.commnet.service.implementation.CommentReader;
import com.sickgyun.server.commnet.service.implementation.CommentUpdater;
import com.sickgyun.server.commnet.service.implementation.CommentValidator;
Expand All @@ -23,6 +24,7 @@ public class CommandCommentService {
private final CommentReader commentReader;
private final CommentCreator commentCreator;
private final CommentUpdater commentUpdater;
private final CommentDeleter commentDeleter;
private final CommentValidator commentValidator;

public void createComment(Long qnaId, User writer, Comment comment) {
Expand All @@ -35,4 +37,10 @@ public void updateComment(Long commentId, Comment comment, User writer) {
commentValidator.validateWriter(updatableComment, writer);
commentUpdater.update(updatableComment, comment);
}

public void deleteComment(Long commentId, User writer) {
Comment comment = commentReader.read(commentId);
commentValidator.validateWriter(comment, writer);
commentDeleter.delete(comment);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.sickgyun.server.commnet.service.implementation;

import org.springframework.stereotype.Service;

import com.sickgyun.server.commnet.domain.Comment;
import com.sickgyun.server.commnet.domain.repository.CommentRepository;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class CommentDeleter {

private final CommentRepository commentRepository;

public void delete(Comment comment) {
commentRepository.delete(comment);
}
}

0 comments on commit 73bf592

Please sign in to comment.