diff --git a/backend/app/Comment/UseCases/CreateComment/CreateComment.php b/backend/app/Comment/UseCases/CreateComment/CreateComment.php new file mode 100644 index 0000000..1987b5d --- /dev/null +++ b/backend/app/Comment/UseCases/CreateComment/CreateComment.php @@ -0,0 +1,49 @@ +postId <= 0) { + throw new BadRequestException('postId must be positive'); + } + if ($request->userId <= 0) { + throw new BadRequestException('userId must be positive'); + } + $body = $request->body === null ? '' : trim($request->body); + if ($body === '') { + throw new BadRequestException('body is required'); + } + + if ($this->postRepo->find($request->postId) === null) { + throw new DomainException('post not found'); + } + + return $this->commentRepo->create(new CreateCommentDto( + postId: $request->postId, + userId: $request->userId, + body: $body, + createdAt: $this->clock->now(), + )); + } +} diff --git a/backend/app/Comment/UseCases/CreateComment/CreateCommentRequest.php b/backend/app/Comment/UseCases/CreateComment/CreateCommentRequest.php new file mode 100644 index 0000000..d2984bb --- /dev/null +++ b/backend/app/Comment/UseCases/CreateComment/CreateCommentRequest.php @@ -0,0 +1,12 @@ +