add null guards in create plan use case
This commit is contained in:
parent
02244b6ed9
commit
3775607503
1 changed files with 13 additions and 0 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Plan\UseCases;
|
||||
|
||||
use App\Exceptions\BadRequestException;
|
||||
use App\Node\NodeRepository;
|
||||
use App\Plan\CreatePlanDto;
|
||||
use App\Plan\Plan;
|
||||
|
|
@ -28,6 +29,18 @@ class CreatePlan
|
|||
*/
|
||||
public function execute(CreatePlanRequest $request): Plan
|
||||
{
|
||||
if ($request->userId === null) {
|
||||
throw new BadRequestException('userId is required');
|
||||
}
|
||||
|
||||
if ($request->textId === null) {
|
||||
throw new BadRequestException('textId is required');
|
||||
}
|
||||
|
||||
if ($request->name === null) {
|
||||
throw new BadRequestException('name is required');
|
||||
}
|
||||
|
||||
$userId = $request->userId;
|
||||
$user = $this->userRepo->find($userId);
|
||||
if ($user === null) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue