implement GetPost use case
validates id > 0, delegates to PostRepository->find. 58 tests pass.
This commit is contained in:
parent
eb0ebc6f63
commit
7fda18dde3
1 changed files with 26 additions and 0 deletions
26
backend/app/Post/UseCases/GetPost/GetPost.php
Normal file
26
backend/app/Post/UseCases/GetPost/GetPost.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue