add set edits
This commit is contained in:
parent
f8e1ef1397
commit
53d4120e83
8 changed files with 245 additions and 0 deletions
|
|
@ -4,10 +4,13 @@ namespace App\Controllers;
|
|||
|
||||
use App\Element\ElementRepository;
|
||||
use App\Exceptions\BadRequestException;
|
||||
use App\Exceptions\NotFoundException;
|
||||
use App\Set\Set as DomainSet;
|
||||
use App\Set\SetRepository;
|
||||
use App\Set\UseCases\CreateSetWithRoot\CreateSetWithRoot;
|
||||
use App\Set\UseCases\CreateSetWithRoot\CreateSetWithRootRequest;
|
||||
use App\Set\UseCases\UpdateSet\UpdateSet;
|
||||
use App\Set\UseCases\UpdateSet\UpdateSetRequest;
|
||||
use App\Shared\Files\Filesystem;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
|
@ -19,6 +22,7 @@ class SetController
|
|||
private SetRepository $setRepository,
|
||||
private ElementRepository $elementRepository,
|
||||
private CreateSetWithRoot $createSetWithRoot,
|
||||
private UpdateSet $updateSet,
|
||||
private Filesystem $filesystem,
|
||||
) {
|
||||
}
|
||||
|
|
@ -61,6 +65,37 @@ class SetController
|
|||
], 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, ?int $id): JsonResponse
|
||||
{
|
||||
$iconImage = $this->uploadedFileInput($request, 'iconImage');
|
||||
|
||||
try {
|
||||
$set = $this->updateSet->execute(
|
||||
new UpdateSetRequest(
|
||||
id: $id,
|
||||
name: $this->stringInput($request, 'name'),
|
||||
description: $this->stringInput($request, 'description'),
|
||||
iconImageContents: $iconImage['contents'],
|
||||
iconImageOriginalName: $iconImage['originalName'],
|
||||
iconImageMimeType: $iconImage['mimeType'],
|
||||
iconImageSizeBytes: $iconImage['sizeBytes'],
|
||||
)
|
||||
);
|
||||
} catch (BadRequestException $exception) {
|
||||
return new JsonResponse([
|
||||
'error' => $exception->getMessage(),
|
||||
], 400);
|
||||
} catch (NotFoundException $exception) {
|
||||
return new JsonResponse([
|
||||
'error' => $exception->getMessage(),
|
||||
], 404);
|
||||
}
|
||||
|
||||
return new JsonResponse([
|
||||
'set' => $this->buildSetPayload($set),
|
||||
], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{
|
||||
* id: int,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue