From 4a4e046de43d08a08fde042dd994dba84341302e Mon Sep 17 00:00:00 2001 From: yisroel Date: Wed, 6 May 2026 15:23:21 +0300 Subject: [PATCH] implement CreatePost use case trims title and body, rejects empty (post-trim) values with BadRequest. supplies createdAt from injected Clock. persists through PostRepository->create and returns the resulting Post. 44 tests pass. --- .../Post/UseCases/CreatePost/CreatePost.php | 40 +++++++++++++++++++ .../UseCases/CreatePost/CreatePostRequest.php | 12 ++++++ 2 files changed, 52 insertions(+) create mode 100644 backend/app/Post/UseCases/CreatePost/CreatePost.php create mode 100644 backend/app/Post/UseCases/CreatePost/CreatePostRequest.php diff --git a/backend/app/Post/UseCases/CreatePost/CreatePost.php b/backend/app/Post/UseCases/CreatePost/CreatePost.php new file mode 100644 index 0000000..0008a08 --- /dev/null +++ b/backend/app/Post/UseCases/CreatePost/CreatePost.php @@ -0,0 +1,40 @@ +title === null ? '' : trim($request->title); + $body = $request->body === null ? '' : trim($request->body); + + if ($title === '') { + throw new BadRequestException('title is required'); + } + if ($body === '') { + throw new BadRequestException('body is required'); + } + + return $this->postRepo->create(new CreatePostDto( + userId: $request->userId, + title: $title, + body: $body, + createdAt: $this->clock->now(), + )); + } +} diff --git a/backend/app/Post/UseCases/CreatePost/CreatePostRequest.php b/backend/app/Post/UseCases/CreatePost/CreatePostRequest.php new file mode 100644 index 0000000..c3aea18 --- /dev/null +++ b/backend/app/Post/UseCases/CreatePost/CreatePostRequest.php @@ -0,0 +1,12 @@ +