mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
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(
|
||||
* path = "poll/{id}/comment",
|
||||
* name = "new_comment",
|
||||
@ -186,12 +187,24 @@ class DefaultController extends AbstractController {
|
||||
$serializer = SerializerBuilder::create()->build();
|
||||
$comment = $serializer->deserialize( $data, 'App\Entity\Comment', 'json' );
|
||||
|
||||
$em = $this->getDoctrine()->getRepository( Owner::class );
|
||||
$foundOwner = $em->find( 10 );
|
||||
$em = $this->getDoctrine()->getRepository( Owner::class );
|
||||
|
||||
$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 )
|
||||
->setPoll( $poll );
|
||||
$foundOwner->addComment( $comment );
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist( $foundOwner );
|
||||
$em->persist( $comment );
|
||||
$em->flush();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user