mirror of
https://github.com/wallabag/wallabag.git
synced 2024-04-29 16:08:44 +00:00
6aca334d53
Mostly using autowiring to inject deps. The only tricky part was for import because all producer use the same class and have a different alias. So we must write them down in the service definition, autowiring doesn't work in that case. Usually: - if a controller has a constructor, it means injected services are at least re-used once in actions - otherwise, service are injected per action
45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Wallabag\ApiBundle\Controller;
|
|
|
|
use JMS\Serializer\SerializationContext;
|
|
use JMS\Serializer\SerializerInterface;
|
|
use Nelmio\ApiDocBundle\Annotation\Operation;
|
|
use Swagger\Annotations as SWG;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
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"
|
|
* )
|
|
* )
|
|
*
|
|
* @Route("/api/config.{_format}", methods={"GET"}, name="api_get_config", defaults={"_format": "json"})
|
|
*
|
|
* @return JsonResponse
|
|
*/
|
|
public function getConfigAction(SerializerInterface $serializer)
|
|
{
|
|
$this->validateAuthentication();
|
|
|
|
$json = $serializer->serialize(
|
|
$this->getUser()->getConfig(),
|
|
'json',
|
|
SerializationContext::create()->setGroups(['config_api'])
|
|
);
|
|
|
|
return (new JsonResponse())
|
|
->setJson($json)
|
|
->setStatusCode(JsonResponse::HTTP_OK);
|
|
}
|
|
}
|