implement GetPost use case

validates id > 0, delegates to PostRepository->find. 58 tests
pass.
This commit is contained in:
yisroel 2026-05-06 15:25:56 +03:00
parent eb0ebc6f63
commit 7fda18dde3
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -0,0 +1,26 @@
<?php
namespace App\Post\UseCases\GetPost;
use App\Exceptions\BadRequestException;
use App\Post\Post;
use App\Post\PostRepository;
class GetPost
{
public function __construct(
private PostRepository $postRepo,
) {}
/**
* @throws BadRequestException
*/
public function execute(int $id): ?Post
{
if ($id <= 0) {
throw new BadRequestException('id must be positive');
}
return $this->postRepo->find($id);
}
}