mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Use annoations for serialization
This commit is contained in:
@@ -138,7 +138,12 @@ class ApiController extends AbstractCRUDController
|
||||
return $response;
|
||||
}
|
||||
|
||||
return $this->json($entity);
|
||||
return $this->json(
|
||||
$entity,
|
||||
Response::HTTP_OK,
|
||||
[],
|
||||
$this->getContextForSerializationPostAlter($action, $request, $_format, $entity)
|
||||
);
|
||||
}
|
||||
|
||||
protected function onAfterValidation(string $action, Request $request, string $_format, $entity, ConstraintViolationListInterface $errors): ?Response
|
||||
@@ -276,7 +281,26 @@ class ApiController extends AbstractCRUDController
|
||||
|
||||
protected function getContextForSerialization(string $action, Request $request, string $_format, $entity): array
|
||||
{
|
||||
return [];
|
||||
switch ($request->getMethod()) {
|
||||
case Request::METHOD_GET:
|
||||
return [ 'groups' => [ 'read' ]];
|
||||
case Request::METHOD_PUT:
|
||||
case Request::METHOD_PATCH:
|
||||
return [ 'groups' => [ 'write' ]];
|
||||
default:
|
||||
throw new \LogicException("get context for serialization is not implemented for this method");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the context for serialization post alter query (in case of
|
||||
* PATCH, PUT, or POST method)
|
||||
*
|
||||
* This is called **after** the entity was altered.
|
||||
*/
|
||||
protected function getContextForSerializationPostAlter(string $action, Request $request, string $_format, $entity): array
|
||||
{
|
||||
return [ 'groups' => [ 'read' ]];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user