20 lines
613 B
PHP
20 lines
613 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
namespace App\Dashboard;
|
|
|
|
use App\Http\{Request, Response};
|
|
use App\Auth\SessionStore;
|
|
use App\Repository\EventRepository;
|
|
|
|
final class EventListController
|
|
{
|
|
public function __construct(private EventRepository $events, private SessionStore $sess) {}
|
|
|
|
public function json(Request $req): Response
|
|
{
|
|
if ($this->sess->get('user_id') === null) return Response::json(['error' => 'unauthorized'], 401);
|
|
$severity = $req->query('severity');
|
|
$rows = $this->events->recent(100, $severity);
|
|
return Response::json(['events' => $rows], 200);
|
|
}
|
|
}
|