add null guards in create plan use case

This commit is contained in:
Yisroel Baum 2026-04-19 23:13:08 +03:00
parent 02244b6ed9
commit 3775607503
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -2,6 +2,7 @@
namespace App\Plan\UseCases; namespace App\Plan\UseCases;
use App\Exceptions\BadRequestException;
use App\Node\NodeRepository; use App\Node\NodeRepository;
use App\Plan\CreatePlanDto; use App\Plan\CreatePlanDto;
use App\Plan\Plan; use App\Plan\Plan;
@ -28,6 +29,18 @@ class CreatePlan
*/ */
public function execute(CreatePlanRequest $request): Plan 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; $userId = $request->userId;
$user = $this->userRepo->find($userId); $user = $this->userRepo->find($userId);
if ($user === null) { if ($user === null) {