From 1c0812f0c2c4112a170c088c8c8ec31a2d121545 Mon Sep 17 00:00:00 2001 From: Dominik Bohuncak Date: Thu, 22 Jun 2023 15:06:53 +0200 Subject: [PATCH] doplnenie search endpointu --- .gitignore | 2 ++ application/public/index.php | 13 +++++---- .../src/Handler/GetIssueSearchHandler.php | 28 +++++++++++++++++++ .../src/Service/AtlassianApiService.php | 13 +++++++-- docker/local/docker-compose.yml | 2 +- 5 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 application/src/Handler/GetIssueSearchHandler.php diff --git a/.gitignore b/.gitignore index 4b3bd3e..1c03726 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ docker/local/docker-compose.compiled.yml /temp/ /application/vendor/ +.env +.env.local diff --git a/application/public/index.php b/application/public/index.php index 33b9d72..0d172ce 100644 --- a/application/public/index.php +++ b/application/public/index.php @@ -1,5 +1,6 @@ handle($request); - return new \GuzzleHttp\Psr7\Response( - $result->getStatusCode(), - $headers, - json_encode($result) - ); + return $handler->handle($request); } catch (\Exception $e) { $response = $response->withStatus(500); $response->getBody()->write($e->getMessage()); @@ -58,6 +54,11 @@ function callAtlassian(HandlerInterface $handler, Request $request, Response $re return callAtlassian($handler, $request, $response); }); +$app->get('/issue/search', function (Request $request, Response $response, $args) { + $handler = new GetIssueSearchHandler(); + return callAtlassian($handler, $request, $response); +}); + $app->post('/issue/idea', function (Request $request, Response $response, $args) { $handler = new SendIdeaHandler(); return callAtlassian($handler, $request, $response); diff --git a/application/src/Handler/GetIssueSearchHandler.php b/application/src/Handler/GetIssueSearchHandler.php new file mode 100644 index 0000000..f786977 --- /dev/null +++ b/application/src/Handler/GetIssueSearchHandler.php @@ -0,0 +1,28 @@ +atlassianApi = new AtlassianApiService(); + } + + /** + * @throws GuzzleException + */ + public function handle(ServerRequestInterface $request): ResponseInterface + { + return $this->atlassianApi->getSearchData($request->getQueryParams()); + } +} diff --git a/application/src/Service/AtlassianApiService.php b/application/src/Service/AtlassianApiService.php index 2638201..4359bd3 100644 --- a/application/src/Service/AtlassianApiService.php +++ b/application/src/Service/AtlassianApiService.php @@ -16,7 +16,6 @@ class AtlassianApiService public function __construct() { - $this->client = new Client([ 'base_uri' => getenv('jira_api_host'), 'headers' => [ @@ -33,10 +32,18 @@ public function __construct() */ public function sendIssue(AttlassianIssueModel $data): ResponseInterface { - $response = $this->client->post('servicedeskapi/request', [ + return $this->client->post('servicedeskapi/request', [ RequestOptions::JSON => $data->toArray(), ]); + } - return $response; + /** + * @throws GuzzleException + */ + public function getSearchData(array $searchData): ResponseInterface + { + return $this->client->get('api/2/search', [ + RequestOptions::QUERY => $searchData, + ]); } } diff --git a/docker/local/docker-compose.yml b/docker/local/docker-compose.yml index 9967495..5adf807 100644 --- a/docker/local/docker-compose.yml +++ b/docker/local/docker-compose.yml @@ -18,5 +18,5 @@ services: - "9080:80" - "9020:9000" volumes: - - ./najsluzby_api:/app + - ./najsluzby_api/application:/app - ../../.ssh:/root/.ssh