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