mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Chill\MainBundle\Controller;
|
|
|
|
use Chill\MainBundle\CRUD\Controller\ApiController;
|
|
use Chill\MainBundle\Entity\Address;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
|
|
|
class AddressApiController extends ApiController
|
|
{
|
|
/**
|
|
* Duplicate an existing address.
|
|
*
|
|
* @Route("/api/1.0/main/address/{id}/duplicate.json", name="chill_api_main_address_duplicate",
|
|
* methods={"POST"})
|
|
*/
|
|
public function duplicate(Address $address): JsonResponse
|
|
{
|
|
$this->denyAccessUnlessGranted('ROLE_USER');
|
|
$new = Address::createFromAddress($address);
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$em->persist($new);
|
|
$em->flush();
|
|
|
|
return $this->json($new, Response::HTTP_OK, [], [
|
|
AbstractNormalizer::GROUPS => ['read'],
|
|
]);
|
|
}
|
|
}
|