add comment action with a new owner
This commit is contained in:
parent
f3d7b0773d
commit
130cd313c0
|
@ -171,6 +171,7 @@ class DefaultController extends AbstractController {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* add a comment on a poll
|
||||||
* @Post(
|
* @Post(
|
||||||
* path = "poll/{id}/comment",
|
* path = "poll/{id}/comment",
|
||||||
* name = "new_comment",
|
* name = "new_comment",
|
||||||
|
@ -187,11 +188,23 @@ class DefaultController extends AbstractController {
|
||||||
$comment = $serializer->deserialize( $data, 'App\Entity\Comment', 'json' );
|
$comment = $serializer->deserialize( $data, 'App\Entity\Comment', 'json' );
|
||||||
|
|
||||||
$em = $this->getDoctrine()->getRepository( Owner::class );
|
$em = $this->getDoctrine()->getRepository( Owner::class );
|
||||||
$foundOwner = $em->find( 10 );
|
|
||||||
|
$data = json_decode( $data, true );
|
||||||
|
|
||||||
|
$foundOwner = $em->findByEmail( $data[ 'owner' ][ 'email' ] );
|
||||||
|
// manage existing or new Owner
|
||||||
|
if ( ! $foundOwner ) {
|
||||||
|
$foundOwner = new Owner();
|
||||||
|
$foundOwner->setPseudo( $data[ 'owner' ][ 'email' ] )
|
||||||
|
->setEmail( $data[ 'owner' ][ 'email' ] )
|
||||||
|
->setModifierToken( uniqid() );
|
||||||
|
}
|
||||||
$comment->setOwner( $foundOwner )
|
$comment->setOwner( $foundOwner )
|
||||||
->setPoll( $poll );
|
->setPoll( $poll );
|
||||||
|
$foundOwner->addComment( $comment );
|
||||||
|
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$em->persist( $foundOwner );
|
||||||
$em->persist( $comment );
|
$em->persist( $comment );
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue