Create REST action to delete orphan visits

This commit is contained in:
Alejandro Celaya
2023-05-18 09:04:28 +02:00
parent abcf2f86be
commit bdfb220126
4 changed files with 89 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
<?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\Core\Visit\VisitsDeleterInterface;
use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware;
class DeleteOrphanVisitsAction extends AbstractRestAction
{
use PagerfantaUtilsTrait;
protected const ROUTE_PATH = '/visits/orphan';
protected const ROUTE_ALLOWED_METHODS = [self::METHOD_DELETE];
public function __construct(private readonly VisitsDeleterInterface $visitsDeleter)
{
}
public function handle(ServerRequestInterface $request): ResponseInterface
{
$apiKey = AuthenticationMiddleware::apiKeyFromRequest($request);
$result = $this->visitsDeleter->deleteOrphanVisits($apiKey);
return new JsonResponse($result->toArray('deletedVisits'));
}
}