mirror of
https://github.com/shlinkio/shlink.git
synced 2026-02-28 04:03:12 +08:00
41 lines
1.4 KiB
PHP
41 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Shlinkio\Shlink\Rest\Action\Visit;
|
|
|
|
use Laminas\Diactoros\Response\JsonResponse;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use Shlinkio\Shlink\Common\Paginator\Util\PagerfantaUtilsTrait;
|
|
use Shlinkio\Shlink\Common\Rest\DataTransformerInterface;
|
|
use Shlinkio\Shlink\Core\Visit\Model\OrphanVisitsParams;
|
|
use Shlinkio\Shlink\Core\Visit\VisitsStatsHelperInterface;
|
|
use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
|
|
use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware;
|
|
|
|
class OrphanVisitsAction extends AbstractRestAction
|
|
{
|
|
use PagerfantaUtilsTrait;
|
|
|
|
protected const ROUTE_PATH = '/visits/orphan';
|
|
protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET];
|
|
|
|
public function __construct(
|
|
private readonly VisitsStatsHelperInterface $visitsHelper,
|
|
private readonly DataTransformerInterface $orphanVisitTransformer,
|
|
) {
|
|
}
|
|
|
|
public function handle(ServerRequestInterface $request): ResponseInterface
|
|
{
|
|
$params = OrphanVisitsParams::fromRawData($request->getQueryParams());
|
|
$apiKey = AuthenticationMiddleware::apiKeyFromRequest($request);
|
|
$visits = $this->visitsHelper->orphanVisits($params, $apiKey);
|
|
|
|
return new JsonResponse([
|
|
'visits' => $this->serializePaginator($visits, $this->orphanVisitTransformer),
|
|
]);
|
|
}
|
|
}
|