1
0
mirror of https://framagit.org/tykayn/date-poll-api synced 2023-08-25 08:23:11 +02:00

return arrays as such

This commit is contained in:
Baptiste Lemoine 2020-01-21 12:55:03 +01:00
parent a98f830800
commit 150dc50003
10 changed files with 119 additions and 10 deletions

4
.env
View File

@ -27,3 +27,7 @@ APP_SECRET=597b0529ac702d27dcb9089f7e69c362
# IMPORTANT: You MUST also configure your db driver and server_version in config/packages/doctrine.yaml # IMPORTANT: You MUST also configure your db driver and server_version in config/packages/doctrine.yaml
DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_name DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_name
###< doctrine/doctrine-bundle ### ###< doctrine/doctrine-bundle ###
###> nelmio/cors-bundle ###
CORS_ALLOW_ORIGIN=^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$
###< nelmio/cors-bundle ###

1
.htaccess Normal file
View File

@ -0,0 +1 @@
Header set Access-Control-Allow-Origin "*"

View File

@ -5,9 +5,11 @@
"php": "^7.1.3", "php": "^7.1.3",
"ext-ctype": "*", "ext-ctype": "*",
"ext-iconv": "*", "ext-iconv": "*",
"ext-json": "*",
"friendsofsymfony/rest-bundle": "^2.6", "friendsofsymfony/rest-bundle": "^2.6",
"jms/serializer-bundle": "^3.4", "jms/serializer-bundle": "^3.4",
"nelmio/api-doc-bundle": "^3.4", "nelmio/api-doc-bundle": "^3.4",
"nelmio/cors-bundle": "^2.0",
"sensio/framework-extra-bundle": "^5.5", "sensio/framework-extra-bundle": "^5.5",
"symfony/console": "4.3.*", "symfony/console": "4.3.*",
"symfony/dotenv": "4.3.*", "symfony/dotenv": "4.3.*",
@ -18,8 +20,7 @@
"symfony/maker-bundle": "^1.14", "symfony/maker-bundle": "^1.14",
"symfony/orm-pack": "^1.0", "symfony/orm-pack": "^1.0",
"symfony/validator": "4.3.*", "symfony/validator": "4.3.*",
"symfony/yaml": "4.3.*", "symfony/yaml": "4.3.*"
"ext-json": "*"
}, },
"require-dev": { "require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.2", "doctrine/doctrine-fixtures-bundle": "^3.2",

64
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "fa70b5946a14ecedaa82c3754b1601e7", "content-hash": "41bf5f0471bb141a097830cb05bbf807",
"packages": [ "packages": [
{ {
"name": "doctrine/annotations", "name": "doctrine/annotations",
@ -2489,6 +2489,63 @@
], ],
"time": "2019-02-18T16:27:10+00:00" "time": "2019-02-18T16:27:10+00:00"
}, },
{
"name": "nelmio/cors-bundle",
"version": "2.0.1",
"source": {
"type": "git",
"url": "https://github.com/nelmio/NelmioCorsBundle.git",
"reference": "9683e6d30d000ef998919261329d825de7c53499"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nelmio/NelmioCorsBundle/zipball/9683e6d30d000ef998919261329d825de7c53499",
"reference": "9683e6d30d000ef998919261329d825de7c53499",
"shasum": ""
},
"require": {
"symfony/framework-bundle": "^4.3 || ^5.0"
},
"require-dev": {
"mockery/mockery": "^1.2",
"symfony/phpunit-bridge": "^4.3 || ^5.0"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Nelmio\\CorsBundle\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nelmio",
"homepage": "http://nelm.io"
},
{
"name": "Symfony Community",
"homepage": "https://github.com/nelmio/NelmioCorsBundle/contributors"
}
],
"description": "Adds CORS (Cross-Origin Resource Sharing) headers support in your Symfony application",
"keywords": [
"api",
"cors",
"crossdomain"
],
"time": "2019-11-15T08:54:08+00:00"
},
{ {
"name": "nikic/php-parser", "name": "nikic/php-parser",
"version": "v4.2.5", "version": "v4.2.5",
@ -5707,6 +5764,7 @@
"code", "code",
"zf" "zf"
], ],
"abandoned": "laminas/laminas-code",
"time": "2019-10-05T23:18:22+00:00" "time": "2019-10-05T23:18:22+00:00"
}, },
{ {
@ -5761,6 +5819,7 @@
"events", "events",
"zf2" "zf2"
], ],
"abandoned": "laminas/laminas-eventmanager",
"time": "2018-04-25T15:33:34+00:00" "time": "2018-04-25T15:33:34+00:00"
}, },
{ {
@ -6068,7 +6127,8 @@
"platform": { "platform": {
"php": "^7.1.3", "php": "^7.1.3",
"ext-ctype": "*", "ext-ctype": "*",
"ext-iconv": "*" "ext-iconv": "*",
"ext-json": "*"
}, },
"platform-dev": [] "platform-dev": []
} }

View File

@ -12,4 +12,5 @@ return [
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true], Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
Nelmio\ApiDocBundle\NelmioApiDocBundle::class => ['all' => true], Nelmio\ApiDocBundle\NelmioApiDocBundle::class => ['all' => true],
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true], Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
]; ];

View File

@ -0,0 +1,15 @@
nelmio_cors:
defaults:
origin_regex: true
allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']
allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
allow_headers: ['Content-Type', 'Authorization']
expose_headers: ['Link']
max_age: 3600
paths:
'^/': null
'^/api/':
allow_origin: ['*']
allow_headers: ['Content-Type', 'Authorization']
allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
max_age: 3600

View File

@ -0,0 +1,15 @@
nelmio_cors:
defaults:
origin_regex: true
allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']
allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
allow_headers: ['Content-Type', 'Authorization']
expose_headers: ['Link']
max_age: 3600
paths:
'^/': null
'^/api/':
allow_origin: ['*']
allow_headers: ['X-Custom-Auth']
allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
max_age: 3600

View File

@ -226,13 +226,13 @@ class DefaultController extends AbstractController {
$stacks = []; $stacks = [];
$choices = []; $choices = [];
foreach ( $poll->getComments() as $c ) { foreach ( $poll->getComments() as $c ) {
$comments[ $c->getId() ] = $c->display(); $comments[] = $c->display();
} }
foreach ( $poll->getStacksOfVotes() as $c ) { foreach ( $poll->getStacksOfVotes() as $c ) {
$stacks[ $c->getId() ] = $c->display(); $stacks[] = $c->display();
} }
foreach ( $poll->getChoices() as $c ) { foreach ( $poll->getChoices() as $c ) {
$choices[ $c->getId() ] = $c->display(); $choices[] = $c->display();
} }
$returnedPoll = [ $returnedPoll = [
'message' => 'your poll config', 'message' => 'your poll config',

View File

@ -50,7 +50,7 @@ class StackOfVotes {
'votes' => [], 'votes' => [],
]; ];
foreach ( $this->getVotes() as $vote ) { foreach ( $this->getVotes() as $vote ) {
$tab[ 'votes' ][ $vote->getId() ] = [ $tab[ 'votes' ][] = [
'id' => $this->getId(), 'id' => $this->getId(),
'vote_id' => $vote->getId(), 'vote_id' => $vote->getId(),
'value' => $vote->getValue(), 'value' => $vote->getValue(),

View File

@ -183,6 +183,18 @@
"config/routes/nelmio_api_doc.yaml" "config/routes/nelmio_api_doc.yaml"
] ]
}, },
"nelmio/cors-bundle": {
"version": "1.5",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "1.5",
"ref": "6388de23860284db9acce0a7a5d9d13153bcb571"
},
"files": [
"config/packages/nelmio_cors.yaml"
]
},
"nikic/php-parser": { "nikic/php-parser": {
"version": "v4.2.4" "version": "v4.2.4"
}, },