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
|
||||
php bin/console doctrine:schema:drop --force
|
||||
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
|
||||
```bash
|
||||
|
@ -225,10 +225,19 @@ class DefaultController extends AbstractController {
|
||||
$stacks = [];
|
||||
$choices = [];
|
||||
foreach ( $poll->getComments() as $c ) {
|
||||
$comments[] = $c;
|
||||
$comments[] = [
|
||||
'pseudo' => $c->getOwner()->getPseudo(),
|
||||
'date' => $c->getCreatedAt(),
|
||||
'text' => $c->getText(),
|
||||
];
|
||||
}
|
||||
foreach ( $poll->getStacksOfVotes() as $c ) {
|
||||
$stacks[] = $c;
|
||||
$stacks[] =
|
||||
[
|
||||
"id" => $c->getId(),
|
||||
"pseudo" => $c->getOwner()->getPseudo(),
|
||||
"votes" => $c->getVotes(),
|
||||
];
|
||||
}
|
||||
foreach ( $poll->getChoices() as $c ) {
|
||||
$choices[] = $c;
|
||||
@ -343,7 +352,7 @@ class DefaultController extends AbstractController {
|
||||
|
||||
$data = json_decode( $data, true );
|
||||
|
||||
$foundOwner = $em->findByEmail( $data[ 'owner' ][ 'email' ] );
|
||||
$foundOwner = $em->findOneByEmail( $data[ 'email' ] );
|
||||
// manage existing or new Owner
|
||||
if ( ! $foundOwner ) {
|
||||
$foundOwner = new Owner();
|
||||
@ -352,6 +361,7 @@ class DefaultController extends AbstractController {
|
||||
->setModifierToken( uniqid() );
|
||||
}
|
||||
$comment->setOwner( $foundOwner )
|
||||
->setCreatedAt( new \DateTime() )
|
||||
->setPoll( $poll );
|
||||
$foundOwner->addComment( $comment );
|
||||
|
||||
@ -362,6 +372,10 @@ class DefaultController extends AbstractController {
|
||||
|
||||
return $this->json( [
|
||||
'message' => 'you created a comment',
|
||||
'data' => [
|
||||
'your_comment' => $comment,
|
||||
'poll_comments' => $poll->getComments(),
|
||||
],
|
||||
],
|
||||
201 );
|
||||
}
|
||||
|
@ -4,9 +4,11 @@ namespace App\Entity;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* @ORM\Entity(repositoryClass="App\Repository\CommentRepository")
|
||||
* @Serializer\ExclusionPolicy("all")
|
||||
*/
|
||||
class Comment {
|
||||
/**
|
||||
@ -18,21 +20,29 @@ class Comment {
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="comments")
|
||||
* @Serializer\Type("App\Entity\Owner")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
private $owner;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text")
|
||||
* @Serializer\Type("string")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
private $text;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime")
|
||||
* @Serializer\Type("datetime")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
private $createdAt;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="comments")
|
||||
* @Serializer\Type("App\Entity\Poll")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
private $poll;
|
||||
|
||||
|
@ -15,17 +15,20 @@ class Vote {
|
||||
* for a date kind, the choice linked is equivalent to the value selected
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @Serializer\Type("string")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $value;
|
||||
/**
|
||||
* @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"})
|
||||
* @Serializer\Type("datetime")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $creationDate;
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Choice", inversedBy="votes", cascade={"persist"})
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
* @Serializer\Type("App\Entity\choice")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $choice;
|
||||
/**
|
||||
@ -33,6 +36,7 @@ class Vote {
|
||||
* @ORM\GeneratedValue()
|
||||
* @ORM\Column(type="integer")
|
||||
* @Serializer\Type("integer")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
private $id;
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user