Added search term filtering to short codes list

This commit is contained in:
Alejandro Celaya
2016-10-22 12:40:51 +02:00
parent 4c76e17178
commit 543c0e62d0
6 changed files with 59 additions and 26 deletions

View File

@@ -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,
];
}
}