-
-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce duplication in actions listing visits
- Loading branch information
Showing
9 changed files
with
87 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shlinkio\Shlink\Rest\Action\Visit; | ||
|
||
use Laminas\Diactoros\Response\JsonResponse; | ||
use Pagerfanta\Pagerfanta; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Shlinkio\Shlink\Common\Paginator\Util\PagerfantaUtils; | ||
use Shlinkio\Shlink\Core\Visit\Entity\Visit; | ||
use Shlinkio\Shlink\Core\Visit\Model\VisitsParams; | ||
use Shlinkio\Shlink\Core\Visit\VisitsStatsHelperInterface; | ||
use Shlinkio\Shlink\Rest\Action\AbstractRestAction; | ||
use Shlinkio\Shlink\Rest\Entity\ApiKey; | ||
use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware; | ||
|
||
abstract class AbstractListVisitsAction extends AbstractRestAction | ||
{ | ||
public function __construct(protected readonly VisitsStatsHelperInterface $visitsHelper) | ||
{ | ||
} | ||
|
||
public function handle(ServerRequestInterface $request): ResponseInterface | ||
{ | ||
$params = VisitsParams::fromRawData($request->getQueryParams()); | ||
$apiKey = AuthenticationMiddleware::apiKeyFromRequest($request); | ||
$visits = $this->getVisitsPaginator($request, $params, $apiKey); | ||
|
||
return new JsonResponse(['visits' => PagerfantaUtils::serializePaginator($visits)]); | ||
} | ||
|
||
/** | ||
* @return Pagerfanta<Visit> | ||
*/ | ||
abstract protected function getVisitsPaginator( | ||
ServerRequestInterface $request, | ||
VisitsParams $params, | ||
ApiKey $apiKey, | ||
): Pagerfanta; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters