shortUrlService = $shortUrlService; $this->translator = $translator; } /** * @param Request $request * @param DelegateInterface $delegate * @return null|Response * @throws \InvalidArgumentException */ public function process(Request $request, DelegateInterface $delegate) { try { $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); return new JsonResponse([ 'error' => RestUtils::UNKNOWN_ERROR, 'message' => $this->translator->translate('Unexpected error occurred'), ], self::STATUS_INTERNAL_SERVER_ERROR); } } /** * @param array $query * @return array */ public function queryToListParams(array $query) { return [ isset($query['page']) ? $query['page'] : 1, isset($query['searchTerm']) ? $query['searchTerm'] : null, isset($query['tags']) ? $query['tags'] : [], isset($query['orderBy']) ? $query['orderBy'] : null, ]; } }