mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
⚡ advance on posting a comment on a poll
This commit is contained in:
parent
7e79048b59
commit
d6fe2a6285
@ -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',
|
||||
] );
|
||||
|
Loading…
x
Reference in New Issue
Block a user