-
-
Notifications
You must be signed in to change notification settings - Fork 625
Expand file tree
/
Copy pathUpdateCapacityAssignmentAction.php
More file actions
51 lines (45 loc) · 2 KB
/
UpdateCapacityAssignmentAction.php
File metadata and controls
51 lines (45 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace HiEvents\Http\Actions\CapacityAssignments;
use HiEvents\DomainObjects\EventDomainObject;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Http\Request\CapacityAssigment\UpsertCapacityAssignmentRequest;
use HiEvents\Resources\CapacityAssignment\CapacityAssignmentResource;
use HiEvents\Services\Application\Handlers\CapacityAssignment\DTO\UpsertCapacityAssignmentDTO;
use HiEvents\Services\Application\Handlers\CapacityAssignment\UpdateCapacityAssignmentHandler;
use HiEvents\Services\Domain\Product\Exception\UnrecognizedProductIdException;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
class UpdateCapacityAssignmentAction extends BaseAction
{
public function __construct(
private readonly UpdateCapacityAssignmentHandler $updateCapacityAssignmentHandler,
)
{
}
public function __invoke(int $eventId, int $capacityAssignmentId, UpsertCapacityAssignmentRequest $request): JsonResponse
{
$this->isActionAuthorized($eventId, EventDomainObject::class);
try {
$assignment = $this->updateCapacityAssignmentHandler->handle(
UpsertCapacityAssignmentDTO::fromArray([
'id' => $capacityAssignmentId,
'name' => $request->validated('name'),
'event_id' => $eventId,
'capacity' => $request->validated('capacity'),
'applies_to' => $request->validated('applies_to'),
'status' => $request->validated('status'),
'product_ids' => $request->validated('product_ids'),
]),
);
} catch (UnrecognizedProductIdException $exception) {
return $this->errorResponse(
message: $exception->getMessage(),
statusCode: Response::HTTP_UNPROCESSABLE_ENTITY,
);
}
return $this->resourceResponse(
resource: CapacityAssignmentResource::class,
data: $assignment,
);
}
}