route set updates
This commit is contained in:
parent
b2e39a98e4
commit
7428612316
7 changed files with 252 additions and 89 deletions
42
backend/app/Set/UseCases/UpdateSet/UpdateDescription.php
Normal file
42
backend/app/Set/UseCases/UpdateSet/UpdateDescription.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace App\Set\UseCases\UpdateSet;
|
||||
|
||||
use App\Exceptions\BadRequestException;
|
||||
use App\Exceptions\NotFoundException;
|
||||
use App\Set\Set;
|
||||
use App\Set\SetRepository;
|
||||
|
||||
class UpdateDescription
|
||||
{
|
||||
public function __construct(private SetRepository $setRepository)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BadRequestException
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function execute(UpdateDescriptionRequest $request): Set
|
||||
{
|
||||
if ($request->id === null) {
|
||||
throw new BadRequestException('setId is required');
|
||||
}
|
||||
|
||||
if (
|
||||
$request->description === null
|
||||
|| trim($request->description) === ''
|
||||
) {
|
||||
throw new BadRequestException('description is required');
|
||||
}
|
||||
|
||||
$set = $this->setRepository->find($request->id);
|
||||
if ($set === null) {
|
||||
throw new NotFoundException('Set not found');
|
||||
}
|
||||
|
||||
$set->setDescription($request->description);
|
||||
|
||||
return $this->setRepository->update($set);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue