2019-01-06 09:57:09 +01:00
|
|
|
<?php
|
2020-10-15 00:19:31 +02:00
|
|
|
|
2021-07-19 07:53:45 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-01-06 09:57:09 +01:00
|
|
|
namespace App\Controller\Api\Admin;
|
|
|
|
|
2021-04-21 23:15:52 +02:00
|
|
|
use App\Controller\Api\AbstractApiCrudController;
|
2019-01-06 09:57:09 +01:00
|
|
|
use App\Entity;
|
2019-09-10 18:40:31 +02:00
|
|
|
use App\Exception\ValidationException;
|
2019-08-09 17:00:21 +02:00
|
|
|
use App\Http\Response;
|
|
|
|
use App\Http\ServerRequest;
|
2020-06-26 22:22:53 +02:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
2019-08-07 06:33:55 +02:00
|
|
|
use OpenApi\Annotations as OA;
|
2019-01-06 09:57:09 +01:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
use Symfony\Component\Serializer\Serializer;
|
|
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
|
|
|
|
2021-07-19 07:53:45 +02:00
|
|
|
/**
|
|
|
|
* @extends AbstractApiCrudController<Entity\Settings>
|
|
|
|
*/
|
2021-04-21 23:15:52 +02:00
|
|
|
class SettingsController extends AbstractApiCrudController
|
2019-01-06 09:57:09 +01:00
|
|
|
{
|
2019-09-29 09:50:24 +02:00
|
|
|
public function __construct(
|
2021-04-23 07:24:12 +02:00
|
|
|
protected Entity\Repository\SettingsRepository $settingsRepo,
|
2020-06-26 22:22:53 +02:00
|
|
|
EntityManagerInterface $em,
|
2019-09-29 09:50:24 +02:00
|
|
|
Serializer $serializer,
|
2021-04-23 07:24:12 +02:00
|
|
|
ValidatorInterface $validator
|
2019-09-29 09:50:24 +02:00
|
|
|
) {
|
2021-04-21 23:15:52 +02:00
|
|
|
parent::__construct($em, $serializer, $validator);
|
2019-01-06 09:57:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @OA\Get(path="/admin/settings",
|
|
|
|
* tags={"Administration: Settings"},
|
|
|
|
* description="List the current values of all editable system settings.",
|
|
|
|
* @OA\Response(response=200, description="Success",
|
2020-12-04 09:41:55 +01:00
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Settings")
|
2019-01-06 09:57:09 +01:00
|
|
|
* ),
|
|
|
|
* @OA\Response(response=403, description="Access denied"),
|
|
|
|
* security={{"api_key": {}}},
|
|
|
|
* )
|
|
|
|
*
|
2019-08-09 17:00:21 +02:00
|
|
|
* @param ServerRequest $request
|
|
|
|
* @param Response $response
|
2019-01-06 09:57:09 +01:00
|
|
|
*/
|
2019-08-09 17:00:21 +02:00
|
|
|
public function listAction(ServerRequest $request, Response $response): ResponseInterface
|
2019-01-06 09:57:09 +01:00
|
|
|
{
|
2020-12-10 23:46:03 +01:00
|
|
|
$settings = $this->settingsRepo->readSettings();
|
2021-04-21 23:15:52 +02:00
|
|
|
return $response->withJson($this->toArray($settings));
|
2019-01-06 09:57:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @OA\Put(path="/admin/settings",
|
|
|
|
* tags={"Administration: Settings"},
|
|
|
|
* description="Update settings to modify any settings provided.",
|
|
|
|
* @OA\RequestBody(
|
2020-12-04 09:41:55 +01:00
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Settings")
|
2019-01-06 09:57:09 +01:00
|
|
|
* ),
|
|
|
|
* @OA\Response(response=200, description="Success",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Api_Status")
|
|
|
|
* ),
|
|
|
|
* @OA\Response(response=403, description="Access denied"),
|
|
|
|
* security={{"api_key": {}}},
|
|
|
|
* )
|
|
|
|
*
|
2019-08-09 17:00:21 +02:00
|
|
|
* @param ServerRequest $request
|
|
|
|
* @param Response $response
|
2019-09-20 18:44:38 +02:00
|
|
|
*
|
2019-09-10 18:40:31 +02:00
|
|
|
* @throws ValidationException
|
2019-01-06 09:57:09 +01:00
|
|
|
*/
|
2019-08-09 17:00:21 +02:00
|
|
|
public function updateAction(ServerRequest $request, Response $response): ResponseInterface
|
2019-01-06 09:57:09 +01:00
|
|
|
{
|
2021-04-21 23:15:52 +02:00
|
|
|
$settings = $this->settingsRepo->readSettings();
|
2021-07-19 07:53:45 +02:00
|
|
|
$this->editRecord((array)$request->getParsedBody(), $settings);
|
2019-01-06 09:57:09 +01:00
|
|
|
|
2019-08-09 17:00:21 +02:00
|
|
|
return $response->withJson(new Entity\Api\Status());
|
2019-01-06 09:57:09 +01:00
|
|
|
}
|
|
|
|
}
|