From c40e39c4adf91aa99a83965d5ad43e718268803f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Danyi?= Date: Fri, 15 Sep 2017 14:00:38 +0200 Subject: [PATCH] * url parameter options added --- config/routes.php | 1 + src/App/Action/HomePageAction.php | 4 +++- src/App/Service/JiraCollectorService.php | 12 +++++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/config/routes.php b/config/routes.php index 359aac4..dbcbf07 100644 --- a/config/routes.php +++ b/config/routes.php @@ -27,5 +27,6 @@ */ $app->get('/', App\Action\HomePageAction::class, 'home'); +$app->get('/{jiraQueryName}[/{filterId:\d+}]', App\Action\HomePageAction::class, 'home.params'); $app->get('/api/ping', App\Action\PingAction::class, 'api.ping'); $app->get('/api/dbg', App\Action\DbgAction::class, 'api.dbg'); diff --git a/src/App/Action/HomePageAction.php b/src/App/Action/HomePageAction.php index c3b6b70..3b52aff 100644 --- a/src/App/Action/HomePageAction.php +++ b/src/App/Action/HomePageAction.php @@ -23,8 +23,10 @@ class HomePageAction implements ServerMiddlewareInterface public function process(ServerRequestInterface $request, DelegateInterface $delegate) { + $queryName = $request->getAttribute('jiraQueryName', 'default'); + $filterId = $request->getAttribute('filterId'); $data = [ - 'chartRows' => $this->jiraService->getChartData(), + 'chartRows' => $this->jiraService->getChartData($queryName, $filterId), ]; return new HtmlResponse($this->template->render('app::home-page', $data)); diff --git a/src/App/Service/JiraCollectorService.php b/src/App/Service/JiraCollectorService.php index f2f06d4..84bcfb6 100644 --- a/src/App/Service/JiraCollectorService.php +++ b/src/App/Service/JiraCollectorService.php @@ -33,9 +33,9 @@ class JiraCollectorService $this->config = $config; } - public function getChartData() + public function getChartData(string $queryName, $filterId) { - $supportTickets = $this->getSupportJiraTickets(); + $supportTickets = $this->getSupportJiraTickets($queryName, $filterId); $openTickets = array_values(array_filter($supportTickets, function(JiraIssue $ticket){ return $ticket->getResolvedAt() === null; })); @@ -63,16 +63,18 @@ class JiraCollectorService } /** + * @param string $queryName + * @param $filterId * @return array|null */ - public function getSupportJiraTickets(): ?array + public function getSupportJiraTickets(string $queryName, $filterId): ?array { $user = $this->config->get('jira.user'); $password = $this->config->get('jira.password'); - $jiraResultUrl = $this->config->get('jira.query'); + $jiraResultUrl = $this->config->get(sprintf('jira.query.%s', $queryName)); $response = $this->httpClient - ->setUri($jiraResultUrl) + ->setUri($filterId ? sprintf($jiraResultUrl, $filterId) : $jiraResultUrl) ->setAuth($user, $password) ->send();