diff --git a/backend/app/Post/UseCases/DeletePost/DeletePost.php b/backend/app/Post/UseCases/DeletePost/DeletePost.php new file mode 100644 index 0000000..b6fa928 --- /dev/null +++ b/backend/app/Post/UseCases/DeletePost/DeletePost.php @@ -0,0 +1,42 @@ +postId <= 0) { + throw new BadRequestException('postId must be positive'); + } + if ($request->requesterId <= 0) { + throw new BadRequestException('requesterId must be positive'); + } + + $post = $this->postRepo->find($request->postId); + if ($post === null) { + return; + } + + $isAuthor = $post->getUserId() === $request->requesterId; + if (! $isAuthor && ! $request->requesterIsAdmin) { + throw new ForbiddenException( + 'requester is not allowed to delete this post' + ); + } + + $this->postRepo->delete($request->postId); + } +} diff --git a/backend/app/Post/UseCases/DeletePost/DeletePostRequest.php b/backend/app/Post/UseCases/DeletePost/DeletePostRequest.php new file mode 100644 index 0000000..a62f2a5 --- /dev/null +++ b/backend/app/Post/UseCases/DeletePost/DeletePostRequest.php @@ -0,0 +1,12 @@ +