add null guards in bulk create nodes use case
This commit is contained in:
parent
337017fc52
commit
1f76fc08b6
1 changed files with 17 additions and 0 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Node\UseCases;
|
||||
|
||||
use App\Exceptions\BadRequestException;
|
||||
use App\Node\CreateNodeDto;
|
||||
use App\Node\Node;
|
||||
use App\Node\NodeRepository;
|
||||
|
|
@ -21,6 +22,22 @@ class BulkCreateNodes
|
|||
*/
|
||||
public function execute(BulkCreateNodesRequest $request): array
|
||||
{
|
||||
if ($request->textId === null) {
|
||||
throw new BadRequestException('textId is required');
|
||||
}
|
||||
|
||||
if ($request->parentNodeId === null) {
|
||||
throw new BadRequestException('parentNodeId is required');
|
||||
}
|
||||
|
||||
if ($request->titlePrefix === null) {
|
||||
throw new BadRequestException('titlePrefix is required');
|
||||
}
|
||||
|
||||
if ($request->count === null) {
|
||||
throw new BadRequestException('count is required');
|
||||
}
|
||||
|
||||
$text = $this->textRepo->find($request->textId);
|
||||
if ($text === null) {
|
||||
throw new DomainException("Text with id: {$request->textId} doesnt exist");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue