Created
December 10, 2021 09:49
-
-
Save aelfannir/f84490c7fc1dc655cbee6b39911405a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//... | |
class Dci | |
{ | |
/** | |
* @Groups("dcis:read", "dcis:write", "medicaments:write") | |
* @ORM\ManyToMany(targetEntity=Medicament::class, inversedBy="dcis", cascade={"persist"}) | |
* | |
*/ | |
private $dci; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//... | |
class Medicament | |
{ | |
/** | |
* @Groups("medicaments:read", "medicaments:write", "dcis:write") | |
* @ORM\ManyToMany(targetEntity=Dci::class, mappedBy="dci", cascade={"persist"}) | |
*/ | |
private $dcis; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//... | |
class ApiController extends AbstractController | |
{ | |
//... | |
public function create(Request $request): JsonResponse | |
{ | |
$object = $request->request->get('object'); | |
$context = [ | |
AbstractNormalizer::GROUPS => ['medicaments:write'] | |
]; | |
$medicament = $this->serializer->denormalize($object, Medicament::class, 'json', $context); | |
return new JsonResponse( | |
$this->serializer->normalize($result), | |
Response::HTTP_CREATED | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment