Commit e9b381c9 authored by Mat's avatar Mat

wip.. image update, pas fini

parent 617fae1b
<?php
namespace APIBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use APIBundle\Form\Image\ImageAPIType;
class ImageController extends MasterAPIController
{
/**
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$image = $em->getRepository('TechnoBundle:Image')
->findOneForAPIUpdate($id);
if ($image === null) {
throw $this->createNotFoundException('Image non trouvée');
}
$form = $this->createForm(ImageAPIType::class, $image);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$em->persist($image);
return $this->api($image);
}
return $this->api($form);
}
/*
$serializer = $this->get('jms_serializer');
$serialized = $serializer->serialize($data, 'json');
return new JsonResponse($serialized, 200, array(), true);
*/
}
<?php
namespace APIBundle\Form\Image;
use Symfony\Component\OptionsResolver\OptionsResolver;
use TechnoBundle\Form\Image\ImageType;
class ImageAPIType extends ImageType
{
/**
*
*/
public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);
$resolver->setDefault('csrf_protection', false);
}
}
......@@ -11,3 +11,11 @@ api_owner_read_one:
defaults:
_controller: APIBundle:Owner:readOne
methods: [ GET ]
api_image_update:
path: /image/{id}
requirements:
id: \d+
defaults:
_controller: APIBundle:Image:update
methods: [ POST ]
......@@ -86,4 +86,21 @@ class ImageRepository extends \Doctrine\ORM\EntityRepository
return $qb->getQuery()->getOneOrNullResult();
}
/**
* @param $id
* @return Image
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneForAPIUpdate($id)
{
$qb = $this->createQueryBuilder('i')
->join('i.owner', 'o')
->addSelect('o')
->where('i.id = :id')
->setParameter(':id', $id);
return $qb->getQuery()->getOneOrNullResult();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment