route set updates

This commit is contained in:
Yisroel Baum 2026-07-03 14:02:08 +03:00
parent b2e39a98e4
commit 7428612316
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
7 changed files with 252 additions and 89 deletions

View file

@ -0,0 +1,39 @@
<?php
namespace App\Set\UseCases\UpdateSet;
use App\Exceptions\BadRequestException;
use App\Exceptions\NotFoundException;
use App\Set\Set;
use App\Set\SetRepository;
class UpdateName
{
public function __construct(private SetRepository $setRepository)
{
}
/**
* @throws BadRequestException
* @throws NotFoundException
*/
public function execute(UpdateNameRequest $request): Set
{
if ($request->id === null) {
throw new BadRequestException('setId is required');
}
if ($request->name === null || trim($request->name) === '') {
throw new BadRequestException('name is required');
}
$set = $this->setRepository->find($request->id);
if ($set === null) {
throw new NotFoundException('Set not found');
}
$set->setName(trim($request->name));
return $this->setRepository->update($set);
}
}