-
-
Notifications
You must be signed in to change notification settings - Fork 665
Expand file tree
/
Copy pathGetEventStatsAction.php
More file actions
34 lines (27 loc) · 1.02 KB
/
Copy pathGetEventStatsAction.php
File metadata and controls
34 lines (27 loc) · 1.02 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
<?php
namespace HiEvents\Http\Actions\Events\Stats;
use HiEvents\DomainObjects\EventDomainObject;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Services\Application\Handlers\Event\DTO\EventStatsRequestDTO;
use HiEvents\Services\Application\Handlers\Event\GetEventStatsHandler;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class GetEventStatsAction extends BaseAction
{
public function __construct(
private readonly GetEventStatsHandler $eventStatsHandler
)
{
}
public function __invoke(int $eventId, Request $request): JsonResponse
{
$this->isActionAuthorized($eventId, EventDomainObject::class);
$dateRangePreset = $request->query('date_range', 'month');
$stats = $this->eventStatsHandler->handle(EventStatsRequestDTO::fromArray([
'event_id' => $eventId,
'date_range_preset' => $dateRangePreset,
]));
return $this->resourceResponse(JsonResource::class, $stats);
}
}