2018-04-20 23:09:18 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Grocy\Controllers;
|
|
|
|
|
|
|
|
use \Grocy\Services\ApplicationService;
|
2018-04-21 19:18:00 +02:00
|
|
|
use \Grocy\Services\ApiKeyService;
|
2018-04-20 23:09:18 +02:00
|
|
|
|
|
|
|
class OpenApiController extends BaseApiController
|
|
|
|
{
|
2018-04-21 19:18:00 +02:00
|
|
|
public function __construct(\Slim\Container $container)
|
|
|
|
{
|
|
|
|
parent::__construct($container);
|
|
|
|
$this->ApiKeyService = new ApiKeyService();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected $ApiKeyService;
|
|
|
|
|
2018-04-20 23:09:18 +02:00
|
|
|
public function DocumentationUi(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
|
|
|
{
|
2018-04-21 19:18:00 +02:00
|
|
|
return $this->AppContainer->view->render($response, 'openapiui');
|
2018-04-20 23:09:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function DocumentationSpec(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
|
|
|
{
|
|
|
|
$applicationService = new ApplicationService();
|
|
|
|
|
2018-05-13 09:00:14 +02:00
|
|
|
$versionInfo = $applicationService->GetInstalledVersion();
|
|
|
|
$this->OpenApiSpec->info->version = $versionInfo->Version;
|
2018-04-22 14:25:08 +02:00
|
|
|
$this->OpenApiSpec->info->description = str_replace('PlaceHolderManageApiKeysUrl', $this->AppContainer->UrlManager->ConstructUrl('/manageapikeys'), $this->OpenApiSpec->info->description);
|
|
|
|
$this->OpenApiSpec->servers[0]->url = $this->AppContainer->UrlManager->ConstructUrl('/api');
|
2018-04-20 23:09:18 +02:00
|
|
|
|
2018-04-22 14:25:08 +02:00
|
|
|
return $this->ApiResponse($this->OpenApiSpec);
|
2018-04-20 23:09:18 +02:00
|
|
|
}
|
2018-04-21 19:18:00 +02:00
|
|
|
|
|
|
|
public function ApiKeysList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
|
|
|
{
|
|
|
|
return $this->AppContainer->view->render($response, 'manageapikeys', [
|
2018-07-25 19:28:15 +02:00
|
|
|
'apiKeys' => $this->Database->api_keys(),
|
|
|
|
'users' => $this->Database->users()
|
2018-04-21 19:18:00 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function CreateNewApiKey(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
|
|
|
{
|
|
|
|
$newApiKey = $this->ApiKeyService->CreateApiKey();
|
|
|
|
$newApiKeyId = $this->ApiKeyService->GetApiKeyId($newApiKey);
|
|
|
|
return $response->withRedirect($this->AppContainer->UrlManager->ConstructUrl("/manageapikeys?CreatedApiKeyId=$newApiKeyId"));
|
|
|
|
}
|
2018-04-20 23:09:18 +02:00
|
|
|
}
|