Skip to content

Commit

Permalink
doplnenie search endpointu
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Bohuncak committed Jun 22, 2023
1 parent d7a2231 commit 1c0812f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
docker/local/docker-compose.compiled.yml
/temp/
/application/vendor/
.env
.env.local
13 changes: 7 additions & 6 deletions application/public/index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Handler\GetIssueSearchHandler;
use App\Handler\HandlerInterface;
use App\Handler\SendIdeaHandler;
use App\Handler\SendProblemHandler;
Expand Down Expand Up @@ -34,12 +35,7 @@ function callAtlassian(HandlerInterface $handler, Request $request, Response $re
];
try {
$request = procesJsonRequest($request);
$result = $handler->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());
Expand All @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions application/src/Handler/GetIssueSearchHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace App\Handler;

use App\Service\AtlassianApiService;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

class GetIssueSearchHandler extends AbstractHandler
{
private AtlassianApiService $atlassianApi;

public function __construct()
{
$this->atlassianApi = new AtlassianApiService();
}

/**
* @throws GuzzleException
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
return $this->atlassianApi->getSearchData($request->getQueryParams());
}
}
13 changes: 10 additions & 3 deletions application/src/Service/AtlassianApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class AtlassianApiService

public function __construct()
{

$this->client = new Client([
'base_uri' => getenv('jira_api_host'),
'headers' => [
Expand All @@ -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,
]);
}
}
2 changes: 1 addition & 1 deletion docker/local/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ services:
- "9080:80"
- "9020:9000"
volumes:
- ./najsluzby_api:/app
- ./najsluzby_api/application:/app
- ../../.ssh:/root/.ssh

0 comments on commit 1c0812f

Please sign in to comment.