mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
⚡ comment data in get poll by id
This commit is contained in:
parent
4c2ff12ca5
commit
6969ff9818
@ -32,7 +32,7 @@ composer install
|
|||||||
```bash
|
```bash
|
||||||
php bin/console doctrine:schema:drop --force
|
php bin/console doctrine:schema:drop --force
|
||||||
php bin/console doctrine:schema:create
|
php bin/console doctrine:schema:create
|
||||||
php bin/console doctrine:fixtures:load --no-interaction
|
php bin/console doctrine:fixtures:load --no-interaction --purge-with-truncate
|
||||||
```
|
```
|
||||||
### launch local server with
|
### launch local server with
|
||||||
```bash
|
```bash
|
||||||
|
@ -225,10 +225,19 @@ class DefaultController extends AbstractController {
|
|||||||
$stacks = [];
|
$stacks = [];
|
||||||
$choices = [];
|
$choices = [];
|
||||||
foreach ( $poll->getComments() as $c ) {
|
foreach ( $poll->getComments() as $c ) {
|
||||||
$comments[] = $c;
|
$comments[] = [
|
||||||
|
'pseudo' => $c->getOwner()->getPseudo(),
|
||||||
|
'date' => $c->getCreatedAt(),
|
||||||
|
'text' => $c->getText(),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
foreach ( $poll->getStacksOfVotes() as $c ) {
|
foreach ( $poll->getStacksOfVotes() as $c ) {
|
||||||
$stacks[] = $c;
|
$stacks[] =
|
||||||
|
[
|
||||||
|
"id" => $c->getId(),
|
||||||
|
"pseudo" => $c->getOwner()->getPseudo(),
|
||||||
|
"votes" => $c->getVotes(),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
foreach ( $poll->getChoices() as $c ) {
|
foreach ( $poll->getChoices() as $c ) {
|
||||||
$choices[] = $c;
|
$choices[] = $c;
|
||||||
@ -343,7 +352,7 @@ class DefaultController extends AbstractController {
|
|||||||
|
|
||||||
$data = json_decode( $data, true );
|
$data = json_decode( $data, true );
|
||||||
|
|
||||||
$foundOwner = $em->findByEmail( $data[ 'owner' ][ 'email' ] );
|
$foundOwner = $em->findOneByEmail( $data[ 'email' ] );
|
||||||
// manage existing or new Owner
|
// manage existing or new Owner
|
||||||
if ( ! $foundOwner ) {
|
if ( ! $foundOwner ) {
|
||||||
$foundOwner = new Owner();
|
$foundOwner = new Owner();
|
||||||
@ -352,6 +361,7 @@ class DefaultController extends AbstractController {
|
|||||||
->setModifierToken( uniqid() );
|
->setModifierToken( uniqid() );
|
||||||
}
|
}
|
||||||
$comment->setOwner( $foundOwner )
|
$comment->setOwner( $foundOwner )
|
||||||
|
->setCreatedAt( new \DateTime() )
|
||||||
->setPoll( $poll );
|
->setPoll( $poll );
|
||||||
$foundOwner->addComment( $comment );
|
$foundOwner->addComment( $comment );
|
||||||
|
|
||||||
@ -362,6 +372,10 @@ class DefaultController extends AbstractController {
|
|||||||
|
|
||||||
return $this->json( [
|
return $this->json( [
|
||||||
'message' => 'you created a comment',
|
'message' => 'you created a comment',
|
||||||
|
'data' => [
|
||||||
|
'your_comment' => $comment,
|
||||||
|
'poll_comments' => $poll->getComments(),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
201 );
|
201 );
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,11 @@ namespace App\Entity;
|
|||||||
|
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use JMS\Serializer\Annotation as Serializer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity(repositoryClass="App\Repository\CommentRepository")
|
* @ORM\Entity(repositoryClass="App\Repository\CommentRepository")
|
||||||
|
* @Serializer\ExclusionPolicy("all")
|
||||||
*/
|
*/
|
||||||
class Comment {
|
class Comment {
|
||||||
/**
|
/**
|
||||||
@ -18,21 +20,29 @@ class Comment {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="comments")
|
* @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="comments")
|
||||||
|
* @Serializer\Type("App\Entity\Owner")
|
||||||
|
* @Serializer\Expose()
|
||||||
*/
|
*/
|
||||||
private $owner;
|
private $owner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="text")
|
* @ORM\Column(type="text")
|
||||||
|
* @Serializer\Type("string")
|
||||||
|
* @Serializer\Expose()
|
||||||
*/
|
*/
|
||||||
private $text;
|
private $text;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="datetime")
|
* @ORM\Column(type="datetime")
|
||||||
|
* @Serializer\Type("datetime")
|
||||||
|
* @Serializer\Expose()
|
||||||
*/
|
*/
|
||||||
private $createdAt;
|
private $createdAt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="comments")
|
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="comments")
|
||||||
|
* @Serializer\Type("App\Entity\Poll")
|
||||||
|
* @Serializer\Expose()
|
||||||
*/
|
*/
|
||||||
private $poll;
|
private $poll;
|
||||||
|
|
||||||
|
@ -15,17 +15,20 @@ class Vote {
|
|||||||
* for a date kind, the choice linked is equivalent to the value selected
|
* for a date kind, the choice linked is equivalent to the value selected
|
||||||
* @ORM\Column(type="string", length=255, nullable=true)
|
* @ORM\Column(type="string", length=255, nullable=true)
|
||||||
* @Serializer\Type("string")
|
* @Serializer\Type("string")
|
||||||
|
* @Serializer\Expose()
|
||||||
*/
|
*/
|
||||||
public $value;
|
public $value;
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"})
|
* @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"})
|
||||||
* @Serializer\Type("datetime")
|
* @Serializer\Type("datetime")
|
||||||
|
* @Serializer\Expose()
|
||||||
*/
|
*/
|
||||||
public $creationDate;
|
public $creationDate;
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="App\Entity\Choice", inversedBy="votes", cascade={"persist"})
|
* @ORM\ManyToOne(targetEntity="App\Entity\Choice", inversedBy="votes", cascade={"persist"})
|
||||||
* @ORM\JoinColumn(nullable=false)
|
* @ORM\JoinColumn(nullable=false)
|
||||||
* @Serializer\Type("App\Entity\choice")
|
* @Serializer\Type("App\Entity\choice")
|
||||||
|
* @Serializer\Expose()
|
||||||
*/
|
*/
|
||||||
public $choice;
|
public $choice;
|
||||||
/**
|
/**
|
||||||
@ -33,6 +36,7 @@ class Vote {
|
|||||||
* @ORM\GeneratedValue()
|
* @ORM\GeneratedValue()
|
||||||
* @ORM\Column(type="integer")
|
* @ORM\Column(type="integer")
|
||||||
* @Serializer\Type("integer")
|
* @Serializer\Type("integer")
|
||||||
|
* @Serializer\Expose()
|
||||||
*/
|
*/
|
||||||
private $id;
|
private $id;
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user