mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
Compare commits
3 Commits
1bc69f56ad
...
d885a3b947
Author | SHA1 | Date | |
---|---|---|---|
d885a3b947 | |||
80abd003ae | |||
a481a41a6c |
150
composer.json
150
composer.json
@ -1,77 +1,81 @@
|
||||
{
|
||||
"type": "project",
|
||||
"license": "proprietary",
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"require": {
|
||||
"php": ">=7.2.5",
|
||||
"ext-ctype": "*",
|
||||
"ext-iconv": "*",
|
||||
"composer/package-versions-deprecated": "1.11.99.1",
|
||||
"doctrine/annotations": "^1.12",
|
||||
"doctrine/doctrine-bundle": "^2.3",
|
||||
"doctrine/doctrine-migrations-bundle": "^3.1",
|
||||
"doctrine/orm": "^2.8",
|
||||
"friendsofsymfony/rest-bundle": "^3.0",
|
||||
"jms/serializer-bundle": "^3.9",
|
||||
"nelmio/cors-bundle": "^2.1",
|
||||
"sensio/framework-extra-bundle": "^6.1",
|
||||
"symfony/asset": "5.2.*",
|
||||
"symfony/console": "5.2.*",
|
||||
"symfony/dotenv": "5.2.*",
|
||||
"symfony/flex": "^1.3.1",
|
||||
"symfony/form": "5.2.*",
|
||||
"symfony/framework-bundle": "5.2.*",
|
||||
"symfony/proxy-manager-bridge": "5.2.*",
|
||||
"symfony/swiftmailer-bundle": "^3.5",
|
||||
"symfony/twig-bundle": "5.2.*",
|
||||
"symfony/yaml": "5.2.*"
|
||||
"type": "project",
|
||||
"license": "aGPLv3",
|
||||
"minimum-stability": "dev",
|
||||
"description": "Une API pour framadate funky",
|
||||
"name": "datepollapi",
|
||||
"prefer-stable": true,
|
||||
"require": {
|
||||
"php": ">=7.2.5",
|
||||
"ext-ctype": "*",
|
||||
"ext-iconv": "*",
|
||||
"composer/package-versions-deprecated": "1.11.99.1",
|
||||
"doctrine/annotations": "^1.12",
|
||||
"doctrine/doctrine-bundle": "^2.3",
|
||||
"doctrine/doctrine-migrations-bundle": "^3.1",
|
||||
"doctrine/orm": "^2.8",
|
||||
"friendsofsymfony/rest-bundle": "^3.0",
|
||||
"jms/serializer-bundle": "^3.9",
|
||||
"nelmio/cors-bundle": "^2.1",
|
||||
"sensio/framework-extra-bundle": "^6.1",
|
||||
"symfony/asset": "5.2.*",
|
||||
"symfony/console": "5.2.*",
|
||||
"symfony/dotenv": "5.2.*",
|
||||
"symfony/flex": "^1.3.1",
|
||||
"symfony/form": "5.2.*",
|
||||
"symfony/framework-bundle": "5.2.*",
|
||||
"symfony/proxy-manager-bridge": "5.2.*",
|
||||
"symfony/swiftmailer-bundle": "^3.5",
|
||||
"symfony/twig-bundle": "5.2.*",
|
||||
"symfony/yaml": "5.2.*",
|
||||
"ext-json": "*"
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
"preferred-install": {
|
||||
"*": "dist"
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
"preferred-install": {
|
||||
"*": "dist"
|
||||
},
|
||||
"sort-packages": true
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"App\\Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"replace": {
|
||||
"symfony/polyfill-ctype": "*",
|
||||
"symfony/polyfill-iconv": "*",
|
||||
"symfony/polyfill-php72": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"auto-scripts": {
|
||||
"cache:clear": "symfony-cmd",
|
||||
"assets:install %PUBLIC_DIR%": "symfony-cmd"
|
||||
},
|
||||
"post-install-cmd": [
|
||||
"@auto-scripts"
|
||||
],
|
||||
"post-update-cmd": [
|
||||
"@auto-scripts"
|
||||
]
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/symfony": "*"
|
||||
},
|
||||
"extra": {
|
||||
"symfony": {
|
||||
"allow-contrib": false,
|
||||
"require": "5.2.*"
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/doctrine-fixtures-bundle": "^3.4",
|
||||
"symfony/maker-bundle": "^1.30"
|
||||
"sort-packages": true
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"App\\Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"replace": {
|
||||
"symfony/polyfill-ctype": "*",
|
||||
"symfony/polyfill-iconv": "*",
|
||||
"symfony/polyfill-php72": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"auto-scripts": {
|
||||
"cache:clear": "symfony-cmd",
|
||||
"assets:install %PUBLIC_DIR%": "symfony-cmd"
|
||||
},
|
||||
"post-install-cmd": [
|
||||
"@auto-scripts"
|
||||
],
|
||||
"post-update-cmd": [
|
||||
"@auto-scripts"
|
||||
]
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/symfony": "*"
|
||||
},
|
||||
"extra": {
|
||||
"symfony": {
|
||||
"allow-contrib": false,
|
||||
"require": "5.2.*"
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/doctrine-fixtures-bundle": "^3.4",
|
||||
"symfony/debug-bundle": "5.2.*",
|
||||
"symfony/maker-bundle": "^1.30"
|
||||
}
|
||||
}
|
||||
|
82
composer.lock
generated
82
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "9c5b89758d62c8a13bd265b1ef64e2bc",
|
||||
"content-hash": "76574cee43242167355502c759b6260c",
|
||||
"packages": [
|
||||
{
|
||||
"name": "composer/package-versions-deprecated",
|
||||
@ -6508,6 +6508,84 @@
|
||||
},
|
||||
"time": "2020-12-20T10:01:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/debug-bundle",
|
||||
"version": "v5.2.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/debug-bundle.git",
|
||||
"reference": "ec21bd26d24dab02ac40e4bec362b3f4032486e8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/debug-bundle/zipball/ec21bd26d24dab02ac40e4bec362b3f4032486e8",
|
||||
"reference": "ec21bd26d24dab02ac40e4bec362b3f4032486e8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-xml": "*",
|
||||
"php": ">=7.2.5",
|
||||
"symfony/http-kernel": "^4.4|^5.0",
|
||||
"symfony/twig-bridge": "^4.4|^5.0",
|
||||
"symfony/var-dumper": "^4.4|^5.0"
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/config": "<4.4",
|
||||
"symfony/dependency-injection": "<5.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/config": "^4.4|^5.0",
|
||||
"symfony/dependency-injection": "^4.4|^5.0",
|
||||
"symfony/web-profiler-bundle": "^4.4|^5.0"
|
||||
},
|
||||
"suggest": {
|
||||
"symfony/config": "For service container configuration",
|
||||
"symfony/dependency-injection": "For using as a service from the container"
|
||||
},
|
||||
"type": "symfony-bundle",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Bundle\\DebugBundle\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Provides a tight integration of the Symfony Debug component into the Symfony full-stack framework",
|
||||
"homepage": "https://symfony.com",
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/debug-bundle/tree/v5.2.4"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-01-10T16:30:10+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/maker-bundle",
|
||||
"version": "v1.30.2",
|
||||
@ -6608,5 +6686,5 @@
|
||||
"ext-iconv": "*"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "1.1.0"
|
||||
"plugin-api-version": "2.0.0"
|
||||
}
|
||||
|
@ -12,4 +12,5 @@ return [
|
||||
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
|
||||
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
|
||||
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
|
||||
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true],
|
||||
];
|
||||
|
4
config/packages/dev/debug.yaml
Normal file
4
config/packages/dev/debug.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
debug:
|
||||
# Forwards VarDumper Data clones to a centralized server allowing to inspect dumps on CLI or in your browser.
|
||||
# See the "server:dump" command to start a new server.
|
||||
dump_destination: "tcp://%env(VAR_DUMPER_SERVER)%"
|
@ -1,5 +1,6 @@
|
||||
# see https://symfony.com/doc/current/reference/configuration/framework.html
|
||||
framework:
|
||||
trusted_hosts: ['localhost:4200', 'localhost']
|
||||
secret: '%env(APP_SECRET)%'
|
||||
#csrf_protection: true
|
||||
#http_method_override: true
|
||||
|
@ -1,24 +1,11 @@
|
||||
nelmio_cors:
|
||||
defaults:
|
||||
allow_credentials: false
|
||||
allow_origin: []
|
||||
allow_headers: []
|
||||
allow_methods: []
|
||||
expose_headers: []
|
||||
max_age: 0
|
||||
hosts: []
|
||||
origin_regex: false
|
||||
forced_allow_origin_value: ~
|
||||
paths:
|
||||
'^/api/':
|
||||
allow_origin: ['*']
|
||||
allow_headers: ['*']
|
||||
allow_methods: ['POST', 'PUT', 'GET', 'DELETE', 'OPTIONS']
|
||||
max_age: 3600
|
||||
'^/':
|
||||
origin_regex: true
|
||||
allow_origin: ['^http://localhost:[0-9]+']
|
||||
allow_headers: ['*']
|
||||
allow_methods: ['POST', 'PUT', 'GET', 'DELETE', 'OPTIONS']
|
||||
max_age: 3600
|
||||
hosts: ['^api\.']
|
||||
defaults:
|
||||
origin_regex: true
|
||||
allow_origin: [ '*' ]
|
||||
allow_methods: [ 'GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE' ]
|
||||
allow_headers: [ '*' ]
|
||||
expose_headers: [ 'Authorization' ]
|
||||
allow_credentials: true
|
||||
max_age: 3600
|
||||
paths:
|
||||
'^/': ~
|
||||
|
@ -5,7 +5,7 @@
|
||||
use Symfony\Component\ErrorHandler\Debug;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
header( 'Access-Control-Allow-Origin: *' );
|
||||
// header( 'Access-Control-Allow-Origin: *' );
|
||||
// header( "Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method" );
|
||||
// header( "Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE" );
|
||||
header( "Allow: GET, POST, OPTIONS, PUT, DELETE" );
|
||||
|
@ -1,269 +1,216 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\api;
|
||||
namespace App\Controller\api;
|
||||
|
||||
use App\Controller\EmailsController;
|
||||
use App\Entity\Choice;
|
||||
use App\Entity\Owner;
|
||||
use App\Entity\Poll;
|
||||
use App\Entity\StackOfVotes;
|
||||
use App\Entity\Vote;
|
||||
use App\Repository\ChoiceRepository;
|
||||
use FOS\RestBundle\Controller\Annotations\Delete;
|
||||
use FOS\RestBundle\Controller\Annotations\Patch;
|
||||
use FOS\RestBundle\Controller\Annotations\Post;
|
||||
use FOS\RestBundle\Controller\Annotations\Route;
|
||||
use JMS\Serializer\SerializerInterface;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use App\Controller\EmailsController;
|
||||
use App\Entity\Comment;
|
||||
use App\Entity\Owner;
|
||||
use App\Entity\Poll;
|
||||
use App\Entity\StackOfVotes;
|
||||
use App\Entity\Vote;
|
||||
use App\Repository\ChoiceRepository;
|
||||
use FOS\RestBundle\Controller\Annotations\Delete;
|
||||
use FOS\RestBundle\Controller\Annotations\Patch;
|
||||
use FOS\RestBundle\Controller\Annotations\Route;
|
||||
use JMS\Serializer\SerializerInterface;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Class DefaultController
|
||||
* @package App\Controller
|
||||
* @Route("/api/v1",name="api_")
|
||||
*/
|
||||
class VoteController extends EmailsController {
|
||||
|
||||
/**
|
||||
* Class DefaultController
|
||||
* @package App\Controller
|
||||
* @Route("/api/v1",name="api_")
|
||||
* add a vote stack on a poll
|
||||
* @Route(
|
||||
* path = "/poll/{custom_url}/answer",
|
||||
* name = "new_vote_stack",
|
||||
* methods={"POST","OPTIONS"}
|
||||
* )
|
||||
*
|
||||
* @param SerializerInterface $serializer
|
||||
* @param string $custom_url
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
class VoteController extends EmailsController {
|
||||
|
||||
/**
|
||||
* add a vote stack on a poll
|
||||
* @Post(
|
||||
* path = "/poll/{custom_url}/answer",
|
||||
* name = "new_vote_stack",
|
||||
* )
|
||||
*
|
||||
* @param SerializerInterface $serializer
|
||||
* @param string $custom_url
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public function newVoteStackAction(
|
||||
SerializerInterface $serializer,
|
||||
string $custom_url,
|
||||
Request $request,
|
||||
ChoiceRepository $choice_repository,
|
||||
public function newVoteStackAction(
|
||||
SerializerInterface $serializer,
|
||||
string $custom_url,
|
||||
Request $request,
|
||||
ChoiceRepository $choice_repository
|
||||
) {
|
||||
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$emPol = $em->getRepository( Poll::class );
|
||||
$poll = $emPol->findOneByCustomUrl( $custom_url );
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$emPol = $em->getRepository( Poll::class );
|
||||
$poll = $emPol->findOneByCustomUrl( $custom_url );
|
||||
|
||||
if ( ! $poll ) {
|
||||
return $this->json( [ 'message' => 'poll "' . $custom_url . '" not found' ], 404 );
|
||||
if ( ! $poll ) {
|
||||
return $this->json( [ 'message' => 'poll "' . $custom_url . '" not found' ], 404 );
|
||||
}
|
||||
|
||||
$data = $request->getContent();
|
||||
$data = json_decode( $data, true );
|
||||
|
||||
// var_dump($data);
|
||||
// die();
|
||||
|
||||
$owner = new Owner();
|
||||
$owner
|
||||
->addPoll( $poll )
|
||||
|
||||
;
|
||||
$newStack = new StackOfVotes();
|
||||
$newStack
|
||||
->setPoll($poll)
|
||||
->setIp( $_SERVER[ 'REMOTE_ADDR' ] )
|
||||
->setPseudo( $data[ "pseudo" ] )
|
||||
->setOwner( $owner );
|
||||
$owner
|
||||
->setPseudo($data['owner'][ "pseudo" ])
|
||||
->setPseudo($data['owner'][ "email" ])
|
||||
->addStackOfVote($newStack);
|
||||
|
||||
// TODO manage new comment
|
||||
$emChoice = $choice_repository;
|
||||
$newComment = new Comment();
|
||||
$newComment->setPseudo($data ['pseudo'])
|
||||
->setPoll($poll)
|
||||
->setText($data['comment']);
|
||||
$owner->addComment($newComment);
|
||||
|
||||
$em->persist($newComment);
|
||||
|
||||
foreach ( $data[ 'votes' ] as $vote ) {
|
||||
if(!$vote[ 'value' ]){
|
||||
continue;
|
||||
}
|
||||
$newVote = new Vote();
|
||||
$newVote->setPoll( $poll );
|
||||
|
||||
$newStack->addVote( $newVote );
|
||||
$choiceFound = $emChoice->find( $vote[ 'choice_id' ] );
|
||||
if ( $choiceFound ) {
|
||||
|
||||
$choiceFound->addVote( $newVote );
|
||||
$newVote->setStacksOfVotes( $newStack )
|
||||
->setChoice( $choiceFound )
|
||||
->setValue( $vote[ 'value' ] );
|
||||
$em->persist( $choiceFound );
|
||||
} else {
|
||||
throw new NotFoundHttpException( 'no choice of id' . $vote[ 'choice_id' ] );
|
||||
}
|
||||
|
||||
$data = $request->getContent();
|
||||
$data = json_decode( $data, true );
|
||||
// $data = $data['data'];
|
||||
$poll->addVote( $newVote );
|
||||
$em->persist( $newVote );
|
||||
}
|
||||
$newStack
|
||||
->setPoll( $poll );
|
||||
$em->persist( $newStack );
|
||||
$em->persist( $poll );
|
||||
$em->flush();
|
||||
|
||||
$owner = new Owner();
|
||||
$owner->addPoll($poll);
|
||||
$newStack = new StackOfVotes();
|
||||
$newStack
|
||||
->setPseudo( $data[ 'pseudo' ] )
|
||||
->setOwner($owner );
|
||||
if ( $poll->getMailOnVote() ) {
|
||||
$this->sendVoteNotificationAction( $newStack->getOwner(), $newStack );
|
||||
}
|
||||
|
||||
// TODO manage new comment
|
||||
$emChoice = $choice_repository;
|
||||
return $this->json( [
|
||||
'poll' => $poll->display(),
|
||||
] );
|
||||
|
||||
foreach ( $data[ 'votes' ] as $vote ) {
|
||||
$newVote = new Vote();
|
||||
$newVote->setPoll($poll);
|
||||
|
||||
$newStack->addVote( $newVote );
|
||||
$choiceFound = $emChoice->find( $vote[ 'choice_id' ] );
|
||||
if ( $choiceFound ) {
|
||||
}
|
||||
|
||||
$choiceFound->addVote( $newVote );
|
||||
$newVote->setStacksOfVotes( $newStack )
|
||||
->setChoice( $choiceFound )
|
||||
->setValue( $vote[ 'value' ] );
|
||||
$em->persist( $choiceFound );
|
||||
} else {
|
||||
throw new NotFoundHttpException( 'no choice of id' . $vote[ 'choice_id' ] );
|
||||
}
|
||||
/**
|
||||
* update vote stack
|
||||
* @Patch(
|
||||
* path = "/vote-stack/{id}/token/{modifierToken}",
|
||||
* name = "update_vote_stack",
|
||||
* requirements = { "id"="\d+"}
|
||||
* )
|
||||
*
|
||||
* @param SerializerInterface $serializer
|
||||
* @param StackOfVotes $id
|
||||
* @param $modifierToken
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public
|
||||
function updateVoteStackAction(
|
||||
SerializerInterface $serializer,
|
||||
StackOfVotes $id,
|
||||
$modifierToken,
|
||||
Request $request
|
||||
) {
|
||||
$voteStack = $id;
|
||||
if ( ! $voteStack ) {
|
||||
return $this->json( [ 'message' => 'vote stack not found' ], 404 );
|
||||
}
|
||||
$poll = $voteStack->getPoll();
|
||||
|
||||
$poll->addVote($newVote);
|
||||
$em->persist( $newVote );
|
||||
}
|
||||
$newStack
|
||||
->setPoll( $poll );
|
||||
$em->persist( $newStack );
|
||||
$em->persist( $poll );
|
||||
// if only self users are allowed to modify a vote, check it
|
||||
if ( ! $modifierToken || $voteStack->getOwner()->getModifierToken() !== $modifierToken ) {
|
||||
return $this->json( [ 'message' => 'your token does not allow you to modify this vote ' ],
|
||||
403 );
|
||||
}
|
||||
// everything is ok, we can update all the votes of the vote stack
|
||||
//TODO
|
||||
// match votes and choices
|
||||
// update answers
|
||||
// save evrything
|
||||
|
||||
|
||||
$jsonResponse = $serializer->serialize( [
|
||||
'message' => 'ok',
|
||||
'modifier_token' => $voteStack->getOwner()->getModifierToken(),
|
||||
'vote_stack' => $voteStack,
|
||||
],
|
||||
'json' );
|
||||
|
||||
$response = new Response( $jsonResponse );
|
||||
$response->headers->set( 'Content-Type', 'application/json' );
|
||||
$response->setStatusCode( 200 );
|
||||
|
||||
return $response;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Delete(
|
||||
* path = "/poll/{id}/votes/{accessToken}",
|
||||
* name = "poll_votes_delete",
|
||||
* requirements = {"accessToken"="\w+", "poll_id"="\d+"}
|
||||
* )
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public
|
||||
function deletePollVotesAction(
|
||||
Poll $poll,
|
||||
$accessToken
|
||||
) {
|
||||
if ( $accessToken == $poll->getAdminKey() ) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$length = count( $poll->getVotes() );
|
||||
$em->remove( $poll->getVotes() );
|
||||
$em->flush();
|
||||
|
||||
|
||||
return $this->json( [
|
||||
'data' => $data,
|
||||
] );
|
||||
// $emOwner = $em->getRepository( Owner::class );
|
||||
// $emChoice = $em->getRepository( Choice::class );
|
||||
// $existingOwner = false;
|
||||
// $foundOwner = $emOwner->findOneByEmail( trim( $data[ 'email' ] ) );
|
||||
// manage existing or new Owner
|
||||
// if ( ! $foundOwner ) {
|
||||
// $foundOwner = new Owner();
|
||||
// $foundOwner
|
||||
// ->setEmail( $data[ 'email' ] )
|
||||
// ->setPseudo( $data[ 'pseudo' ] );
|
||||
// } else {
|
||||
// $existingOwner = true;
|
||||
// }
|
||||
// TODO anti flood
|
||||
// $foundOwner
|
||||
// ->setModifierToken( $poll->generateRandomKey() );
|
||||
// $stack = new StackOfVotes();
|
||||
// $stack
|
||||
// ->setOwner( $foundOwner )
|
||||
// ->setIp( $_SERVER[ 'REMOTE_ADDR' ] )
|
||||
// ->setPseudo( $data[ 'pseudo' ] )
|
||||
// ->setPoll( $custom_url );
|
||||
// foreach ( $data[ 'votes' ] as $voteInfo ) {
|
||||
//
|
||||
// if ( ! isset( $voteInfo[ 'value' ] ) ) {
|
||||
// continue;
|
||||
// }
|
||||
// $allowedValuesToAnswer = [ 'yes', 'maybe', 'no' ];
|
||||
//
|
||||
// if ( ! in_array( $voteInfo[ 'value' ], $allowedValuesToAnswer ) ) {
|
||||
// return $this->json( [
|
||||
// 'message' => 'answer ' . $voteInfo[ 'value' ] . ' is not allowed. should be yes, maybe, or no.',
|
||||
// 'vote_stack' => $stack,
|
||||
// ],
|
||||
// 404 );
|
||||
// }
|
||||
// $vote = new Vote();
|
||||
// $foundChoice = $emChoice->find( $voteInfo[ 'choice_id' ] );
|
||||
// if ( ! $foundChoice ) {
|
||||
// return $this->json( [
|
||||
// 'message' => 'choice ' . $voteInfo[ 'choice_id' ] . ' was not found',
|
||||
// 'vote_stack' => $stack,
|
||||
// ],
|
||||
// 404 );
|
||||
// }
|
||||
// $vote->setPoll( $poll )
|
||||
// ->setChoice( $foundChoice )
|
||||
// ->setValue( $voteInfo[ 'value' ] );
|
||||
// $vote->setPoll( $poll );
|
||||
// $stack->addVote( $vote );
|
||||
// $poll->addVote( $vote );
|
||||
// $em->persist( $vote );
|
||||
// $em->persist( $foundChoice );
|
||||
// }
|
||||
//
|
||||
// // find poll from choices
|
||||
// $poll->addStackOfVote( $stack );
|
||||
// $em->persist( $stack );
|
||||
// $em->persist( $poll );
|
||||
// $em->flush();
|
||||
// $precision = '';
|
||||
// if ( $existingOwner ) {
|
||||
// $precision = ' from an existing owner : ' . $foundOwner->getEmail();
|
||||
// }
|
||||
//
|
||||
// if ( $poll->getMailOnVote() ) {
|
||||
// $this->sendVoteNotificationAction( $stack->getOwner(), $stack );
|
||||
// }
|
||||
//
|
||||
// $returnedVoteStack = $stack;
|
||||
//
|
||||
// $jsonResponse = $serializer->serialize( $returnedVoteStack, 'json' );
|
||||
//
|
||||
// $response = new Response( $jsonResponse );
|
||||
// $response->headers->set( 'Content-Type', 'application/json' );
|
||||
// $response->setStatusCode( 200 );
|
||||
//
|
||||
// return $response;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* update vote stack
|
||||
* @Patch(
|
||||
* path = "/vote-stack/{id}/token/{modifierToken}",
|
||||
* name = "update_vote_stack",
|
||||
* requirements = { "id"="\d+"}
|
||||
* )
|
||||
*
|
||||
* @param SerializerInterface $serializer
|
||||
* @param StackOfVotes $id
|
||||
* @param $modifierToken
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public
|
||||
function updateVoteStackAction(
|
||||
SerializerInterface $serializer,
|
||||
StackOfVotes $id,
|
||||
$modifierToken,
|
||||
Request $request
|
||||
) {
|
||||
$voteStack = $id;
|
||||
if ( ! $voteStack ) {
|
||||
return $this->json( [ 'message' => 'vote stack not found' ], 404 );
|
||||
}
|
||||
$poll = $voteStack->getPoll();
|
||||
|
||||
// if only self users are allowed to modify a vote, check it
|
||||
if ( ! $modifierToken || $voteStack->getOwner()->getModifierToken() !== $modifierToken ) {
|
||||
return $this->json( [ 'message' => 'your token does not allow you to modify this vote ' ],
|
||||
403 );
|
||||
}
|
||||
// everything is ok, we can update all the votes of the vote stack
|
||||
//TODO
|
||||
// match votes and choices
|
||||
// update answers
|
||||
// save evrything
|
||||
|
||||
|
||||
$jsonResponse = $serializer->serialize( [
|
||||
'message' => 'ok',
|
||||
'modifier_token' => $voteStack->getOwner()->getModifierToken(),
|
||||
'vote_stack' => $voteStack,
|
||||
'message' => 'boom! les ' . $length . ' votes du sondage ont été supprimés',
|
||||
],
|
||||
'json' );
|
||||
|
||||
$response = new Response( $jsonResponse );
|
||||
$response->headers->set( 'Content-Type', 'application/json' );
|
||||
$response->setStatusCode( 200 );
|
||||
|
||||
return $response;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Delete(
|
||||
* path = "/poll/{id}/votes/{accessToken}",
|
||||
* name = "poll_votes_delete",
|
||||
* requirements = {"accessToken"="\w+", "poll_id"="\d+"}
|
||||
* )
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public
|
||||
function deletePollVotesAction(
|
||||
Poll $poll,
|
||||
$accessToken
|
||||
) {
|
||||
if ( $accessToken == $poll->getAdminKey() ) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$length = count( $poll->getVotes() );
|
||||
$em->remove( $poll->getVotes() );
|
||||
$em->flush();
|
||||
|
||||
return $this->json( [
|
||||
'message' => 'boom! les ' . $length . ' votes du sondage ont été supprimés',
|
||||
],
|
||||
200 );
|
||||
} else {
|
||||
return $this->json( [
|
||||
'message' => 'le token d\'autorisation est invalide, vous ne pouvez pas modifier ce sondage',
|
||||
],
|
||||
403 );
|
||||
}
|
||||
200 );
|
||||
} else {
|
||||
return $this->json( [
|
||||
'message' => 'le token d\'autorisation est invalide, vous ne pouvez pas modifier ce sondage',
|
||||
],
|
||||
403 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -316,6 +316,19 @@
|
||||
'id' => $choice_id,
|
||||
'url' => $choice_url,
|
||||
'name' => $vote->getChoice()->getName(),
|
||||
'score' => 0,
|
||||
'yes' => [
|
||||
'count' => 0,
|
||||
'people' => [],
|
||||
],
|
||||
'maybe' => [
|
||||
'count' => 0,
|
||||
'people' => [],
|
||||
],
|
||||
'no' => [
|
||||
'count' => 0,
|
||||
'people' => [],
|
||||
],
|
||||
|
||||
];
|
||||
}
|
||||
|
@ -67,15 +67,7 @@ class StackOfVotes {
|
||||
'created_at' => $this->getCreatedAtAsString(),
|
||||
'votes' => [],
|
||||
];
|
||||
// prefill votes with all choices ids
|
||||
// foreach ( $this->getPoll()->getChoices() as $choice ) {
|
||||
// $tab[ 'votes' ][ $choice->getId() ] = [
|
||||
// 'choice_id' => $choice->getId(),
|
||||
// 'value' => null,
|
||||
// ];
|
||||
// }
|
||||
|
||||
foreach ( $votes as $vote ) {
|
||||
foreach ( $this->getVotes() as $vote ) {
|
||||
$tab[ 'votes' ][ $vote->getChoice()->getId() ] = $vote->display();
|
||||
}
|
||||
|
||||
|
12
symfony.lock
12
symfony.lock
@ -216,6 +216,18 @@
|
||||
"bin/console"
|
||||
]
|
||||
},
|
||||
"symfony/debug-bundle": {
|
||||
"version": "4.1",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "master",
|
||||
"version": "4.1",
|
||||
"ref": "f8863cbad2f2e58c4b65fa1eac892ab189971bea"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/dev/debug.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/dependency-injection": {
|
||||
"version": "v5.2.6"
|
||||
},
|
||||
|
@ -25,7 +25,7 @@ cecho g " time to update the framadate setup"
|
||||
cecho g "######################"
|
||||
|
||||
COMMAND_BUILD="build:prod:demobliss"
|
||||
# git reset --hard
|
||||
git reset --hard
|
||||
git pull origin master
|
||||
|
||||
composer install
|
||||
@ -85,7 +85,9 @@ fi
|
||||
|
||||
git config --global diff.submodule log
|
||||
git submodule update
|
||||
git submodule foreach git reset --hard && git checkout master && git pull
|
||||
cd funky-framadate-front
|
||||
git reset --hard && git checkout master && git pull
|
||||
cd ..
|
||||
|
||||
cecho g "######################"
|
||||
cecho g " check dependencies of the frontend with yarn "
|
||||
|
Loading…
Reference in New Issue
Block a user