Skip to content

Commit

Permalink
Merge pull request #115 from Developer-Wikis/feature/#109
Browse files Browse the repository at this point in the history
fix: 댓글 삭제 로직 수정
  • Loading branch information
dhkstnaos authored Dec 8, 2022
2 parents 2c9fffa + 0f92832 commit 6c4006a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.developer.wiki.question.command.domain.Comment;
import com.developer.wiki.question.command.domain.CommentRepository;
import com.developer.wiki.question.command.domain.EntityNotFoundException;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -17,7 +18,12 @@ public class CommentDeleteService {

public void delete(Long id, PasswordRequest passwordRequest, Long userId) {
Comment comment = commentRepository.findById(id).orElseThrow(EntityNotFoundException::new);
comment.matchPassword(passwordRequest.getPassword());
commentRepository.delete(comment);
if (!Objects.isNull(userId)) {
commentRepository.delete(comment);
}
else if(Objects.isNull(userId) && Objects.nonNull(passwordRequest)){
comment.matchPassword(passwordRequest.getPassword());
commentRepository.delete(comment);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class CommentDeleteController {

@DeleteMapping("/{commentId}")
public ResponseEntity<Void> delete(@AuthenticationPrincipal User currentUser,
@PathVariable Long commentId, @RequestBody PasswordRequest passwordRequest) {
@PathVariable Long commentId, @RequestBody(required = false) PasswordRequest passwordRequest) {
Long userId = Objects.isNull(currentUser) ? null : currentUser.getId();
commentDeleteService.delete(commentId, passwordRequest,userId);
return ResponseEntity.ok(null);
Expand Down

0 comments on commit 6c4006a

Please sign in to comment.