From a8f59afc306a9c2b7abc23afeeb83453d5c8cd2d Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Wed, 6 May 2026 22:30:17 +0300 Subject: [PATCH] implement ClearFeaturedPost use case --- .../ClearFeaturedPost/ClearFeaturedPost.php | 48 +++++++++++++++++++ .../ClearFeaturedPostRequest.php | 11 +++++ 2 files changed, 59 insertions(+) create mode 100644 backend/app/Post/UseCases/ClearFeaturedPost/ClearFeaturedPost.php create mode 100644 backend/app/Post/UseCases/ClearFeaturedPost/ClearFeaturedPostRequest.php diff --git a/backend/app/Post/UseCases/ClearFeaturedPost/ClearFeaturedPost.php b/backend/app/Post/UseCases/ClearFeaturedPost/ClearFeaturedPost.php new file mode 100644 index 0000000..4a47ca4 --- /dev/null +++ b/backend/app/Post/UseCases/ClearFeaturedPost/ClearFeaturedPost.php @@ -0,0 +1,48 @@ +requesterIsAdmin) { + throw new ForbiddenException( + 'only admins can unfeature a post' + ); + } + if ($request->postId <= 0) { + throw new BadRequestException('postId must be positive'); + } + + $post = $this->postRepo->find($request->postId); + if ($post === null) { + return; + } + if (! $post->isFeatured()) { + return; + } + + $this->postRepo->update(new Post( + id: $post->getId(), + userId: $post->getUserId(), + title: $post->getTitle(), + body: $post->getBody(), + createdAt: $post->getCreatedAt(), + featureSlot: null, + )); + } +} diff --git a/backend/app/Post/UseCases/ClearFeaturedPost/ClearFeaturedPostRequest.php b/backend/app/Post/UseCases/ClearFeaturedPost/ClearFeaturedPostRequest.php new file mode 100644 index 0000000..1b1f1f4 --- /dev/null +++ b/backend/app/Post/UseCases/ClearFeaturedPost/ClearFeaturedPostRequest.php @@ -0,0 +1,11 @@ +