chill-bundles/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php

48 lines
1.5 KiB
PHP

<?php
namespace Chill\PersonBundle\Controller;
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Serializer\Exception;
use Symfony\Component\Routing\Annotation\Route;
use Chill\MainBundle\CRUD\Controller\ApiController;
use Chill\PersonBundle\Household\MembersEditor;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
class HouseholdMemberController extends ApiController
{
/**
* @Route(
* "/api/1.0/person/household/members/move.{_format}",
* name="chill_person_household_members_move"
* )
*/
public function move(Request $request, $_format): Response
{
try {
$editor = $this->getSerializer()
->deserialize($request->getContent(), MembersEditor::class,
$_format, ['groups' => [ "read" ]]);
} catch (Exception\InvalidArgumentException | Exception\UnexpectedValueException $e) {
throw new BadRequestException("Deserialization error: {$e->getMessage()}", 45896, $e);
}
// TODO ACL
//
// TODO validation
//
$em = $this->getDoctrine()->getManager();
foreach ($editor->getPersistable() as $el) {
$em->persist($el);
}
$em->flush();
return $this->json($editor->getHousehold(), Response::HTTP_OK, [], [
"groups" => ["read"],
]);
}
}