diff --git a/backend/app/Comment/UseCases/DeleteComment/DeleteComment.php b/backend/app/Comment/UseCases/DeleteComment/DeleteComment.php new file mode 100644 index 0000000..daa8798 --- /dev/null +++ b/backend/app/Comment/UseCases/DeleteComment/DeleteComment.php @@ -0,0 +1,42 @@ +commentId <= 0) { + throw new BadRequestException('commentId must be positive'); + } + if ($request->requesterId <= 0) { + throw new BadRequestException('requesterId must be positive'); + } + + $comment = $this->commentRepo->find($request->commentId); + if ($comment === null) { + return; + } + + $isAuthor = $comment->getUserId() === $request->requesterId; + if (! $isAuthor && ! $request->requesterIsAdmin) { + throw new ForbiddenException( + 'requester is not allowed to delete this comment' + ); + } + + $this->commentRepo->delete($request->commentId); + } +} diff --git a/backend/app/Comment/UseCases/DeleteComment/DeleteCommentRequest.php b/backend/app/Comment/UseCases/DeleteComment/DeleteCommentRequest.php new file mode 100644 index 0000000..9dfaa2e --- /dev/null +++ b/backend/app/Comment/UseCases/DeleteComment/DeleteCommentRequest.php @@ -0,0 +1,12 @@ +