remove set creation
This commit is contained in:
parent
f62b05bc37
commit
914cbd37a1
5 changed files with 0 additions and 71 deletions
|
|
@ -1,10 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Set;
|
|
||||||
|
|
||||||
class CreateSetDto
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
public string $name,
|
|
||||||
) {}
|
|
||||||
}
|
|
||||||
|
|
@ -4,15 +4,6 @@ namespace App\Set;
|
||||||
|
|
||||||
class EloquentSetRepository implements SetRepository
|
class EloquentSetRepository implements SetRepository
|
||||||
{
|
{
|
||||||
public function create(CreateSetDto $dto): Set
|
|
||||||
{
|
|
||||||
$model = SetModel::create([
|
|
||||||
'name' => $dto->name,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $this->toDomain($model);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function find(int $id): ?Set
|
public function find(int $id): ?Set
|
||||||
{
|
{
|
||||||
$model = SetModel::find($id);
|
$model = SetModel::find($id);
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,6 @@ namespace App\Set;
|
||||||
|
|
||||||
interface SetRepository
|
interface SetRepository
|
||||||
{
|
{
|
||||||
public function create(CreateSetDto $dto): Set;
|
|
||||||
|
|
||||||
public function find(int $id): ?Set;
|
public function find(int $id): ?Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
<?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