advance on posting a comment on a poll

This commit is contained in:
Baptiste Lemoine 2019-11-06 15:01:39 +01:00
parent 7e79048b59
commit d6fe2a6285
1 changed files with 19 additions and 4 deletions

View File

@ -82,8 +82,7 @@ class DefaultController extends AbstractController {
$timeStamp = time() + ( 3600 * 24 * 90 ); // 90 days by default
$newpoll->setExpiracyDate( ( new \DateTime() )->setTimestamp( $timeStamp ),
new \DateTimeZone( 'Europe/Paris' ) );
$data = json_decode( $data, true );
// die( $data );
$data = json_decode( $data, true );
$em = $this->getDoctrine()->getRepository( Owner::class );
$foundOwner = $em->findOneBy( [ 'email' => $data[ 'owner' ][ 'email' ] ] );
@ -164,10 +163,26 @@ class DefaultController extends AbstractController {
* @Post(
* path = "/comment/new",
* name = "new_comment",
* requirements = {"content"="\w+"}
* requirements = {"content"="\w+", "poll_id"="\d+"}
* )
*/
public function newCommentAction() {
public function newCommentAction( Request $request ) {
$data = $request->getContent();
$serializer = SerializerBuilder::create()->build();
$comment = $serializer->deserialize( $data, 'App\Entity\Comment', 'json' );
$em = $this->getDoctrine()->getRepository( Poll::class );
$foundPoll = $em->findOneBy( [ 'id' => $data[ 'poll_id' ] ] );
$em = $this->getDoctrine()->getRepository( Owner::class );
$foundOwner = $em->find( 10 );
$comment->setOwner( $foundOwner )
->setPoll( $foundPoll );
$em = $this->getDoctrine()->getManager();
$em->persist( $comment );
// $em->persist( $foundOwner );
$em->flush();
return $this->json( [
'message' => 'you created a comment',
] );