mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Added search term filtering to short codes list
This commit is contained in:
@@ -53,8 +53,8 @@ class ListShortcodesAction extends AbstractRestAction
|
||||
public function dispatch(Request $request, Response $response, callable $out = null)
|
||||
{
|
||||
try {
|
||||
$query = $request->getQueryParams();
|
||||
$shortUrls = $this->shortUrlService->listShortUrls(isset($query['page']) ? $query['page'] : 1);
|
||||
$params = $this->queryToListParams($request->getQueryParams());
|
||||
$shortUrls = $this->shortUrlService->listShortUrls(...$params);
|
||||
return new JsonResponse(['shortUrls' => $this->serializePaginator($shortUrls)]);
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error('Unexpected error while listing short URLs.' . PHP_EOL . $e);
|
||||
@@ -64,4 +64,16 @@ class ListShortcodesAction extends AbstractRestAction
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $query
|
||||
* @return string
|
||||
*/
|
||||
public function queryToListParams(array $query)
|
||||
{
|
||||
return [
|
||||
isset($query['page']) ? $query['page'] : 1,
|
||||
isset($query['searchTerm']) ? $query['searchTerm'] : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ class ListShortcodesActionTest extends TestCase
|
||||
public function properListReturnsSuccessResponse()
|
||||
{
|
||||
$page = 3;
|
||||
$this->service->listShortUrls($page)->willReturn(new Paginator(new ArrayAdapter()))
|
||||
->shouldBeCalledTimes(1);
|
||||
$this->service->listShortUrls($page, null)->willReturn(new Paginator(new ArrayAdapter()))
|
||||
->shouldBeCalledTimes(1);
|
||||
|
||||
$response = $this->action->__invoke(
|
||||
ServerRequestFactory::fromGlobals()->withQueryParams([
|
||||
@@ -52,8 +52,8 @@ class ListShortcodesActionTest extends TestCase
|
||||
public function anExceptionsReturnsErrorResponse()
|
||||
{
|
||||
$page = 3;
|
||||
$this->service->listShortUrls($page)->willThrow(\Exception::class)
|
||||
->shouldBeCalledTimes(1);
|
||||
$this->service->listShortUrls($page, null)->willThrow(\Exception::class)
|
||||
->shouldBeCalledTimes(1);
|
||||
|
||||
$response = $this->action->__invoke(
|
||||
ServerRequestFactory::fromGlobals()->withQueryParams([
|
||||
|
||||
Reference in New Issue
Block a user