wallabag/src/Wallabag/ApiBundle/Controller/ConfigRestController.php

45 lines
1.2 KiB
PHP
Raw Normal View History

2022-03-15 09:18:28 +00:00
<?php
namespace Wallabag\ApiBundle\Controller;
2022-03-15 09:44:32 +00:00
use JMS\Serializer\SerializationContext;
2022-08-28 00:01:46 +00:00
use JMS\Serializer\SerializerInterface;
use Nelmio\ApiDocBundle\Annotation\Operation;
use Swagger\Annotations as SWG;
2022-03-15 09:18:28 +00:00
use Symfony\Component\HttpFoundation\JsonResponse;
2022-11-23 11:44:55 +00:00
use Symfony\Component\Routing\Annotation\Route;
2022-03-15 09:18:28 +00:00
class ConfigRestController extends WallabagRestController
{
/**
* Retrieve configuration for current user.
*
* @Operation(
* tags={"Config"},
* summary="Retrieve configuration for current user.",
* @SWG\Response(
* response="200",
* description="Returned when successful"
* )
* )
2022-03-15 09:18:28 +00:00
*
2022-11-23 11:44:55 +00:00
* @Route("/api/config.{_format}", methods={"GET"}, name="api_get_config", defaults={"_format": "json"})
*
2022-03-15 09:18:28 +00:00
* @return JsonResponse
*/
public function getConfigAction(SerializerInterface $serializer)
2022-03-15 09:18:28 +00:00
{
$this->validateAuthentication();
$json = $serializer->serialize(
2022-03-15 09:44:32 +00:00
$this->getUser()->getConfig(),
'json',
SerializationContext::create()->setGroups(['config_api'])
);
return (new JsonResponse())
->setJson($json)
->setStatusCode(JsonResponse::HTTP_OK);
2022-03-15 09:18:28 +00:00
}
}