Rabbi_Gerzi/backend/app/Set/UseCases/UpdateSet/UpdateDescription.php
2026-07-03 14:02:08 +03:00

42 lines
1,015 B
PHP

<?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);
}
}