mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
39 lines
1.0 KiB
PHP
39 lines
1.0 KiB
PHP
<?php
|
|
|
|
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"})
|
|
*
|
|
* @param Address $address
|
|
*/
|
|
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']
|
|
]);
|
|
|
|
}
|
|
|
|
}
|