Files
grocy/controllers/OpenApiController.php
T

44 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace Grocy\Controllers;
class OpenApiController extends BaseApiController
{
2020-02-11 17:42:03 +01:00
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
2020-02-11 17:42:03 +01:00
public function DocumentationUi(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->render($response, 'openapiui');
}
2020-02-11 17:42:03 +01:00
public function DocumentationSpec(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$applicationService = $this->getApplicationService();
2018-05-13 09:00:14 +02:00
$versionInfo = $applicationService->GetInstalledVersion();
$this->getOpenApiSpec()->info->version = $versionInfo->Version;
$this->getOpenApiSpec()->info->description = str_replace('PlaceHolderManageApiKeysUrl', $this->AppContainer->get('UrlManager')->ConstructUrl('/manageapikeys'), $this->getOpenApiSpec()->info->description);
$this->getOpenApiSpec()->servers[0]->url = $this->AppContainer->get('UrlManager')->ConstructUrl('/api');
return $this->ApiResponse($response, $this->getOpenApiSpec());
}
2020-02-11 17:42:03 +01:00
public function ApiKeysList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'manageapikeys', [
'apiKeys' => $this->getDatabase()->api_keys(),
'users' => $this->getDatabase()->users()
]);
}
2020-02-11 17:42:03 +01:00
public function CreateNewApiKey(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$newApiKey = $this->getApiKeyService()->CreateApiKey();
$newApiKeyId = $this->getApiKeyService()->GetApiKeyId($newApiKey);
2020-02-11 17:42:03 +01:00
return $response->withRedirect($this->AppContainer->get('UrlManager')->ConstructUrl("/manageapikeys?CreatedApiKeyId=$newApiKeyId"));
}
}