add set edits
This commit is contained in:
parent
f8e1ef1397
commit
53d4120e83
8 changed files with 245 additions and 0 deletions
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace App\Set;
|
||||
|
||||
use DomainException;
|
||||
|
||||
class EloquentSetRepository implements SetRepository
|
||||
{
|
||||
public function create(CreateSetDto $dto): Set
|
||||
|
|
@ -15,6 +17,35 @@ class EloquentSetRepository implements SetRepository
|
|||
return $this->toDomain($model);
|
||||
}
|
||||
|
||||
public function update(Set $set): Set
|
||||
{
|
||||
$model = SetModel::find($set->getId());
|
||||
if ($model === null) {
|
||||
throw new DomainException(
|
||||
"Set with id: {$set->getId()} doesnt exist"
|
||||
);
|
||||
}
|
||||
|
||||
$model->name = $set->getName();
|
||||
$model->description = $set->getDescription();
|
||||
$model->icon_image_url = $set->getIconImageUrl();
|
||||
$model->save();
|
||||
|
||||
return $this->toDomain($model);
|
||||
}
|
||||
|
||||
public function delete(Set $set): void
|
||||
{
|
||||
$model = SetModel::find($set->getId());
|
||||
if ($model === null) {
|
||||
throw new DomainException(
|
||||
"Set with id: {$set->getId()} doesnt exist"
|
||||
);
|
||||
}
|
||||
|
||||
$model->delete();
|
||||
}
|
||||
|
||||
public function find(int $id): ?Set
|
||||
{
|
||||
$model = SetModel::find($id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue