add set elements
This commit is contained in:
parent
db35a97910
commit
2c4cdabc15
17 changed files with 497 additions and 0 deletions
40
backend/app/Set/UseCases/CreateSet/CreateSet.php
Normal file
40
backend/app/Set/UseCases/CreateSet/CreateSet.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace App\Set\UseCases\CreateSet;
|
||||
|
||||
use App\Element\CreateElementDto;
|
||||
use App\Element\ElementRepository;
|
||||
use App\Exceptions\BadRequestException;
|
||||
use App\Set\CreateSetDto;
|
||||
use App\Set\Set;
|
||||
use App\Set\SetRepository;
|
||||
|
||||
class CreateSet
|
||||
{
|
||||
public function __construct(
|
||||
private SetRepository $setRepo,
|
||||
private ElementRepository $elementRepo,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function execute(CreateSetRequest $request): Set
|
||||
{
|
||||
if ($request->name === null || $request->name === '') {
|
||||
throw new BadRequestException('name is required');
|
||||
}
|
||||
|
||||
$set = $this->setRepo->create(new CreateSetDto(
|
||||
name: $request->name,
|
||||
));
|
||||
|
||||
$this->elementRepo->create(new CreateElementDto(
|
||||
set: $set,
|
||||
title: $set->getName(),
|
||||
parentElement: null,
|
||||
));
|
||||
|
||||
return $set;
|
||||
}
|
||||
}
|
||||
10
backend/app/Set/UseCases/CreateSet/CreateSetRequest.php
Normal file
10
backend/app/Set/UseCases/CreateSet/CreateSetRequest.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\Set\UseCases\CreateSet;
|
||||
|
||||
class CreateSetRequest
|
||||
{
|
||||
public function __construct(
|
||||
public ?string $name,
|
||||
) {}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue