Browse Source

basic api crud ok

master
art.dambrine 4 years ago
parent
commit
32592dcca4
  1. 4
      .env
  2. 2
      .gitignore
  3. 4
      .idea/php.xml
  4. 3
      .idea/src.iml
  5. 2
      composer.json
  6. 322
      composer.lock
  7. 2
      config/bundles.php
  8. 7
      config/packages/api_platform.yaml
  9. 10
      config/packages/nelmio_cors.yaml
  10. 4
      config/routes/api_platform.yaml
  11. 41
      migrations/Version20210326134141.php
  12. 45
      migrations/Version20210326143537.php
  13. 34
      migrations/Version20210326144901.php
  14. 8
      sql/generation.sql
  15. 0
      sql/pokemon.sql
  16. 18
      sql/type.sql
  17. 87
      src/Entity/GenerationPoke.php
  18. 177
      src/Entity/Pokemon.php
  19. 91
      src/Entity/TypePoke.php
  20. 50
      src/Repository/GenerationPokeRepository.php
  21. 50
      src/Repository/PokemonRepository.php
  22. 50
      src/Repository/TypePokeRepository.php
  23. 35
      symfony.lock

4
.env

@ -30,3 +30,7 @@ APP_SECRET=ed4570d9c2866990932c9e834745ba21
# DATABASE_URL="mysql://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7"
DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8"
###< doctrine/doctrine-bundle ###
###> nelmio/cors-bundle ###
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
###< nelmio/cors-bundle ###

2
.gitignore

@ -1,4 +1,4 @@
.idea/
###> symfony/framework-bundle ###
/.env.local
/.env.local.php

4
.idea/php.xml

@ -103,6 +103,10 @@
<path value="$PROJECT_DIR$/vendor/psr/cache" />
<path value="$PROJECT_DIR$/vendor/psr/log" />
<path value="$PROJECT_DIR$/vendor/psr/container" />
<path value="$PROJECT_DIR$/vendor/nelmio/cors-bundle" />
<path value="$PROJECT_DIR$/vendor/willdurand/negotiation" />
<path value="$PROJECT_DIR$/vendor/fig/link-util" />
<path value="$PROJECT_DIR$/vendor/api-platform/core" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="7.2">

3
.idea/src.iml

@ -106,6 +106,9 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/cache" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/log" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/container" />
<excludeFolder url="file://$MODULE_DIR$/.idea/dataSources" />
<excludeFolder url="file://$MODULE_DIR$/var" />
<excludeFolder url="file://$MODULE_DIR$/vendor" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />

2
composer.json

@ -7,11 +7,13 @@
"php": ">=7.2.5",
"ext-ctype": "*",
"ext-iconv": "*",
"api-platform/core": "^2.6",
"composer/package-versions-deprecated": "1.11.99.1",
"doctrine/annotations": "^1.0",
"doctrine/doctrine-bundle": "^2.3",
"doctrine/doctrine-migrations-bundle": "^3.0",
"doctrine/orm": "^2.8",
"nelmio/cors-bundle": "^2.1",
"phpdocumentor/reflection-docblock": "^5.2",
"sensio/framework-extra-bundle": "^5.1",
"symfony/asset": "5.2.*",

322
composer.lock

@ -4,8 +4,162 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "8a9a2eb7d2fd01fec399e0a9a10e4180",
"content-hash": "ae2e9c67c9b1291a357031a97bb24bb9",
"packages": [
{
"name": "api-platform/core",
"version": "v2.6.3",
"source": {
"type": "git",
"url": "https://github.com/api-platform/core.git",
"reference": "1ba77218dfe61ca9e6cff1bbb3e9a4a6658d4538"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/api-platform/core/zipball/1ba77218dfe61ca9e6cff1bbb3e9a4a6658d4538",
"reference": "1ba77218dfe61ca9e6cff1bbb3e9a4a6658d4538",
"shasum": ""
},
"require": {
"doctrine/inflector": "^1.0 || ^2.0",
"fig/link-util": "^1.0",
"php": ">=7.1",
"psr/cache": "^1.0",
"psr/container": "^1.0",
"symfony/http-foundation": "^4.4 || ^5.1",
"symfony/http-kernel": "^4.4 || ^5.1",
"symfony/property-access": "^3.4.19 || ^4.4 || ^5.1",
"symfony/property-info": "^3.4 || ^4.4 || ^5.2.1",
"symfony/serializer": "^4.4 || ^5.1",
"symfony/web-link": "^4.4 || ^5.1",
"willdurand/negotiation": "^2.0.3 || ^3.0"
},
"conflict": {
"doctrine/common": "<2.7",
"doctrine/mongodb-odm": "<2.0",
"doctrine/persistence": "<1.3"
},
"require-dev": {
"behat/behat": "^3.1",
"behat/mink": "^1.7",
"doctrine/annotations": "^1.7",
"doctrine/common": "^2.11 || ^3.0",
"doctrine/data-fixtures": "^1.2.2",
"doctrine/doctrine-bundle": "^1.12 || ^2.0",
"doctrine/mongodb-odm": "^2.0",
"doctrine/mongodb-odm-bundle": "^4.0",
"doctrine/orm": "^2.6.4 || ^3.0",
"elasticsearch/elasticsearch": "^6.0 || ^7.0",
"friends-of-behat/mink-browserkit-driver": "^1.3.1",
"friends-of-behat/mink-extension": "^2.2",
"friends-of-behat/symfony-extension": "^2.1",
"guzzlehttp/guzzle": "^6.0 || ^7.0",
"jangregor/phpstan-prophecy": "^0.8",
"justinrainbow/json-schema": "^5.2.1",
"phpdocumentor/reflection-docblock": "^3.0 || ^4.0 || ^5.1",
"phpdocumentor/type-resolver": "^0.3 || ^0.4 || ^1.4",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.65",
"phpstan/phpstan-doctrine": "^0.12.7",
"phpstan/phpstan-phpunit": "^0.12.4",
"phpstan/phpstan-symfony": "^0.12.4",
"psr/log": "^1.0",
"ramsey/uuid": "^3.7 || ^4.0",
"ramsey/uuid-doctrine": "^1.4",
"soyuka/contexts": "^3.3.1",
"soyuka/stubs-mongodb": "^1.0",
"symfony/asset": "^3.4 || ^4.4 || ^5.1",
"symfony/browser-kit": "^4.4 || ^5.1",
"symfony/cache": "^3.4 || ^4.4 || ^5.1",
"symfony/config": "^3.4 || ^4.4 || ^5.1",
"symfony/console": "^3.4 || ^4.4 || ^5.1",
"symfony/css-selector": "^3.4 || ^4.4 || ^5.1",
"symfony/debug": "^3.4 || ^4.4 || ^5.1",
"symfony/dependency-injection": "^3.4 || ^4.4 || ^5.1",
"symfony/doctrine-bridge": "^3.4 || ^4.4 || ^5.1",
"symfony/dom-crawler": "^3.4 || ^4.4 || ^5.1",
"symfony/event-dispatcher": "^3.4 || ^4.4 || ^5.1",
"symfony/expression-language": "^3.4 || ^4.4 || ^5.1",
"symfony/finder": "^3.4 || ^4.4 || ^5.1",
"symfony/form": "^3.4 || ^4.4 || ^5.1",
"symfony/framework-bundle": "^4.4 || ^5.1",
"symfony/http-client": "^4.4 || ^5.1",
"symfony/mercure-bundle": "*",
"symfony/messenger": "^4.4 || ^5.1",
"symfony/phpunit-bridge": "^5.1.7",
"symfony/routing": "^3.4 || ^4.4 || ^5.1",
"symfony/security-bundle": "^3.4 || ^4.4 || ^5.1",
"symfony/security-core": "^4.4 || ^5.1",
"symfony/twig-bundle": "^3.4 || ^4.4 || ^5.1",
"symfony/validator": "^3.4 || ^4.4 || ^5.1",
"symfony/web-profiler-bundle": "^4.4 || ^5.1",
"symfony/yaml": "^3.4 || ^4.4 || ^5.1",
"twig/twig": "^1.42.3 || ^2.12 || ^3.0",
"webonyx/graphql-php": "^14.0"
},
"suggest": {
"doctrine/mongodb-odm-bundle": "To support MongoDB. Only versions 4.0 and later are supported.",
"elasticsearch/elasticsearch": "To support Elasticsearch.",
"guzzlehttp/guzzle": "To use the HTTP cache invalidation system.",
"ocramius/package-versions": "To display the API Platform's version in the debug bar.",
"phpdocumentor/reflection-docblock": "To support extracting metadata from PHPDoc.",
"psr/cache-implementation": "To use metadata caching.",
"ramsey/uuid": "To support Ramsey's UUID identifiers.",
"symfony/cache": "To have metadata caching when using Symfony integration.",
"symfony/config": "To load XML configuration files.",
"symfony/expression-language": "To use authorization features.",
"symfony/security": "To use authorization features.",
"symfony/twig-bundle": "To use the Swagger UI integration.",
"symfony/uid": "To support Symfony UUID/ULID identifiers.",
"symfony/web-profiler-bundle": "To use the data collector.",
"webonyx/graphql-php": "To support GraphQL."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "2.7.x-dev"
},
"symfony": {
"require": "^3.4 || ^4.4 || ^5.1"
}
},
"autoload": {
"psr-4": {
"ApiPlatform\\Core\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Kévin Dunglas",
"email": "dunglas@gmail.com",
"homepage": "https://dunglas.fr"
}
],
"description": "Build a fully-featured hypermedia or GraphQL API in minutes!",
"homepage": "https://api-platform.com",
"keywords": [
"Hydra",
"JSON-LD",
"api",
"graphql",
"hal",
"jsonapi",
"openapi",
"rest",
"swagger"
],
"funding": [
{
"url": "https://tidelift.com/funding/github/packagist/api-platform/core",
"type": "tidelift"
}
],
"time": "2021-03-07T19:13:33+00:00"
},
{
"name": "composer/package-versions-deprecated",
"version": "1.11.99.1",
@ -1394,6 +1548,63 @@
],
"time": "2021-03-07T14:33:28+00:00"
},
{
"name": "fig/link-util",
"version": "1.1.2",
"source": {
"type": "git",
"url": "https://github.com/php-fig/link-util.git",
"reference": "5d7b8d04ed3393b4b59968ca1e906fb7186d81e8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/link-util/zipball/5d7b8d04ed3393b4b59968ca1e906fb7186d81e8",
"reference": "5d7b8d04ed3393b4b59968ca1e906fb7186d81e8",
"shasum": ""
},
"require": {
"php": ">=5.5.0",
"psr/link": "~1.0@dev"
},
"provide": {
"psr/link-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "^5.1",
"squizlabs/php_codesniffer": "^2.3.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Fig\\Link\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common utility implementations for HTTP links",
"keywords": [
"http",
"http-link",
"link",
"psr",
"psr-13",
"rest"
],
"time": "2021-02-03T23:36:04+00:00"
},
{
"name": "friendsofphp/proxy-manager-lts",
"version": "v1.0.3",
@ -1741,6 +1952,63 @@
],
"time": "2020-12-14T13:15:25+00:00"
},
{
"name": "nelmio/cors-bundle",
"version": "2.1.0",
"source": {
"type": "git",
"url": "https://github.com/nelmio/NelmioCorsBundle.git",
"reference": "be4d5824caebc86da9e224e935e02e1201b3ea54"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nelmio/NelmioCorsBundle/zipball/be4d5824caebc86da9e224e935e02e1201b3ea54",
"reference": "be4d5824caebc86da9e224e935e02e1201b3ea54",
"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": "2020-07-22T11:44:28+00:00"
},
{
"name": "phpdocumentor/reflection-common",
"version": "2.2.0",
@ -7146,6 +7414,58 @@
"validate"
],
"time": "2021-03-09T10:59:23+00:00"
},
{
"name": "willdurand/negotiation",
"version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/willdurand/Negotiation.git",
"reference": "04e14f38d4edfcc974114a07d2777d90c98f3d9c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/willdurand/Negotiation/zipball/04e14f38d4edfcc974114a07d2777d90c98f3d9c",
"reference": "04e14f38d4edfcc974114a07d2777d90c98f3d9c",
"shasum": ""
},
"require": {
"php": ">=7.1.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^5.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"autoload": {
"psr-4": {
"Negotiation\\": "src/Negotiation"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "William Durand",
"email": "will+git@drnd.me"
}
],
"description": "Content Negotiation tools for PHP provided as a standalone library.",
"homepage": "http://williamdurand.fr/Negotiation/",
"keywords": [
"accept",
"content",
"format",
"header",
"negotiation"
],
"time": "2020-09-25T08:01:41+00:00"
}
],
"packages-dev": [

2
config/bundles.php

@ -12,4 +12,6 @@ return [
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
];

7
config/packages/api_platform.yaml

@ -0,0 +1,7 @@
api_platform:
mapping:
paths: ['%kernel.project_dir%/src/Entity']
patch_formats:
json: ['application/merge-patch+json']
swagger:
versions: [3]

10
config/packages/nelmio_cors.yaml

@ -0,0 +1,10 @@
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

4
config/routes/api_platform.yaml

@ -0,0 +1,4 @@
api_platform:
resource: .
type: api_platform
prefix: /api

41
migrations/Version20210326134141.php

@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210326134141 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE generation (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE pokemon (id INT AUTO_INCREMENT NOT NULL, type1_id INT NOT NULL, type2_id INT DEFAULT NULL, generation_id INT NOT NULL, nom VARCHAR(255) NOT NULL, vie INT NOT NULL, attaque INT NOT NULL, defense INT NOT NULL, legendaire TINYINT(1) NOT NULL, INDEX IDX_62DC90F3BFAFA3E1 (type1_id), INDEX IDX_62DC90F3AD1A0C0F (type2_id), INDEX IDX_62DC90F3553A6EC4 (generation_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE type (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE pokemon ADD CONSTRAINT FK_62DC90F3BFAFA3E1 FOREIGN KEY (type1_id) REFERENCES type (id)');
$this->addSql('ALTER TABLE pokemon ADD CONSTRAINT FK_62DC90F3AD1A0C0F FOREIGN KEY (type2_id) REFERENCES type (id)');
$this->addSql('ALTER TABLE pokemon ADD CONSTRAINT FK_62DC90F3553A6EC4 FOREIGN KEY (generation_id) REFERENCES generation (id)');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE pokemon DROP FOREIGN KEY FK_62DC90F3553A6EC4');
$this->addSql('ALTER TABLE pokemon DROP FOREIGN KEY FK_62DC90F3BFAFA3E1');
$this->addSql('ALTER TABLE pokemon DROP FOREIGN KEY FK_62DC90F3AD1A0C0F');
$this->addSql('DROP TABLE generation');
$this->addSql('DROP TABLE pokemon');
$this->addSql('DROP TABLE type');
}
}

45
migrations/Version20210326143537.php

@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210326143537 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE pokemon DROP FOREIGN KEY FK_62DC90F3553A6EC4');
$this->addSql('ALTER TABLE pokemon DROP FOREIGN KEY FK_62DC90F3AD1A0C0F');
$this->addSql('ALTER TABLE pokemon DROP FOREIGN KEY FK_62DC90F3BFAFA3E1');
$this->addSql('CREATE TABLE generation_poke (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE type_poke (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('DROP TABLE generation');
$this->addSql('DROP TABLE pokemon');
$this->addSql('DROP TABLE type');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE generation (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB COMMENT = \'\' ');
$this->addSql('CREATE TABLE pokemon (id INT AUTO_INCREMENT NOT NULL, type1_id INT NOT NULL, type2_id INT DEFAULT NULL, generation_id INT NOT NULL, nom VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, vie INT NOT NULL, attaque INT NOT NULL, defense INT NOT NULL, legendaire TINYINT(1) NOT NULL, INDEX IDX_62DC90F3553A6EC4 (generation_id), INDEX IDX_62DC90F3BFAFA3E1 (type1_id), INDEX IDX_62DC90F3AD1A0C0F (type2_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB COMMENT = \'\' ');
$this->addSql('CREATE TABLE type (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB COMMENT = \'\' ');
$this->addSql('ALTER TABLE pokemon ADD CONSTRAINT FK_62DC90F3553A6EC4 FOREIGN KEY (generation_id) REFERENCES generation (id)');
$this->addSql('ALTER TABLE pokemon ADD CONSTRAINT FK_62DC90F3AD1A0C0F FOREIGN KEY (type2_id) REFERENCES type (id)');
$this->addSql('ALTER TABLE pokemon ADD CONSTRAINT FK_62DC90F3BFAFA3E1 FOREIGN KEY (type1_id) REFERENCES type (id)');
$this->addSql('DROP TABLE generation_poke');
$this->addSql('DROP TABLE type_poke');
}
}

34
migrations/Version20210326144901.php

@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210326144901 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE pokemon (id INT AUTO_INCREMENT NOT NULL, type1_id INT NOT NULL, type2_id INT DEFAULT NULL, generation_id INT DEFAULT NULL, nom VARCHAR(255) NOT NULL, vie INT NOT NULL, attaque INT NOT NULL, defense INT NOT NULL, legendaire TINYINT(1) NOT NULL, INDEX IDX_62DC90F3BFAFA3E1 (type1_id), INDEX IDX_62DC90F3AD1A0C0F (type2_id), INDEX IDX_62DC90F3553A6EC4 (generation_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE pokemon ADD CONSTRAINT FK_62DC90F3BFAFA3E1 FOREIGN KEY (type1_id) REFERENCES type_poke (id)');
$this->addSql('ALTER TABLE pokemon ADD CONSTRAINT FK_62DC90F3AD1A0C0F FOREIGN KEY (type2_id) REFERENCES type_poke (id)');
$this->addSql('ALTER TABLE pokemon ADD CONSTRAINT FK_62DC90F3553A6EC4 FOREIGN KEY (generation_id) REFERENCES generation_poke (id)');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE pokemon');
}
}

8
sql/generation.sql

@ -0,0 +1,8 @@
INSERT INTO generation_poke(Id,Name) VALUES (1,'1 Kanto');
INSERT INTO generation_poke(Id,Name) VALUES (2,'2 Johto');
INSERT INTO generation_poke(Id,Name) VALUES (3,'3 Hoenn');
INSERT INTO generation_poke(Id,Name) VALUES (4,'4 Sinnoh');
INSERT INTO generation_poke(Id,Name) VALUES (5,'5 Unys');
INSERT INTO generation_poke(Id,Name) VALUES (6,'6 Kalos');
INSERT INTO generation_poke(Id,Name) VALUES (7,'7 Alola');
INSERT INTO generation_poke(Id,Name) VALUES (8,'8 Galar');

0
sql/pokemon.sql

18
sql/type.sql

@ -0,0 +1,18 @@
INSERT INTO type_poke(Id,Name) VALUES (1,'Bug');
INSERT INTO type_poke(Id,Name) VALUES (2,'Dark');
INSERT INTO type_poke(Id,Name) VALUES (3,'Dragon');
INSERT INTO type_poke(Id,Name) VALUES (4,'Electric');
INSERT INTO type_poke(Id,Name) VALUES (5,'Fairy');
INSERT INTO type_poke(Id,Name) VALUES (6,'Fighting');
INSERT INTO type_poke(Id,Name) VALUES (7,'Fire');
INSERT INTO type_poke(Id,Name) VALUES (8,'Flying');
INSERT INTO type_poke(Id,Name) VALUES (9,'Ghost');
INSERT INTO type_poke(Id,Name) VALUES (10,'Grass');
INSERT INTO type_poke(Id,Name) VALUES (11,'Ground');
INSERT INTO type_poke(Id,Name) VALUES (12,'Ice');
INSERT INTO type_poke(Id,Name) VALUES (13,'Normal');
INSERT INTO type_poke(Id,Name) VALUES (14,'Poison');
INSERT INTO type_poke(Id,Name) VALUES (15,'Psychic');
INSERT INTO type_poke(Id,Name) VALUES (16,'Rock');
INSERT INTO type_poke(Id,Name) VALUES (17,'Steel');
INSERT INTO type_poke(Id,Name) VALUES (18,'Water');

87
src/Entity/GenerationPoke.php

@ -0,0 +1,87 @@
<?php
namespace App\Entity;
use App\Repository\GenerationPokeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=GenerationPokeRepository::class)
* @ApiResource
*/
class GenerationPoke
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"pokemon_read"})
*/
private $name;
/**
* @ORM\OneToMany(targetEntity=Pokemon::class, mappedBy="generation")
*/
private $pokemon;
public function __construct()
{
$this->pokemon = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection|Pokemon[]
*/
public function getPokemon(): Collection
{
return $this->pokemon;
}
public function addPokemon(Pokemon $pokemon): self
{
if (!$this->pokemon->contains($pokemon)) {
$this->pokemon[] = $pokemon;
$pokemon->setGeneration($this);
}
return $this;
}
public function removePokemon(Pokemon $pokemon): self
{
if ($this->pokemon->removeElement($pokemon)) {
// set the owning side to null (unless already changed)
if ($pokemon->getGeneration() === $this) {
$pokemon->setGeneration(null);
}
}
return $this;
}
}

177
src/Entity/Pokemon.php

@ -0,0 +1,177 @@
<?php
namespace App\Entity;
use App\Repository\PokemonRepository;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=PokemonRepository::class)
* @ApiResource(
* normalizationContext={
* "groups"={"pokemon_read"}
* }
* )
*/
class Pokemon
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"pokemon_read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"pokemon_read"})
*/
private $nom;
/**
* @ORM\ManyToOne(targetEntity=TypePoke::class, inversedBy="pokemon")
* @ORM\JoinColumn(nullable=false)
* @Groups({"pokemon_read"})
*/
private $type1;
/**
* @ORM\ManyToOne(targetEntity=TypePoke::class)
* @Groups({"pokemon_read"})
*/
private $type2;
/**
* @ORM\Column(type="integer")
* @Groups({"pokemon_read"})
*/
private $vie;
/**
* @ORM\Column(type="integer")
* @Groups({"pokemon_read"})
*/
private $attaque;
/**
* @ORM\Column(type="integer")
* @Groups({"pokemon_read"})
*/
private $defense;
/**
* @ORM\Column(type="boolean")
* @Groups({"pokemon_read"})
*/
private $legendaire;
/**
* @ORM\ManyToOne(targetEntity=GenerationPoke::class, inversedBy="pokemon")
* @Groups({"pokemon_read"})
*/
private $generation;
public function getId(): ?int
{
return $this->id;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): self
{
$this->nom = $nom;
return $this;
}
public function getType1(): ?TypePoke
{
return $this->type1;
}
public function setType1(?TypePoke $type1): self
{
$this->type1 = $type1;
return $this;
}
public function getType2(): ?TypePoke
{
return $this->type2;
}
public function setType2(?TypePoke $type2): self
{
$this->type2 = $type2;
return $this;
}
public function getVie(): ?int
{
return $this->vie;
}
public function setVie(int $vie): self
{
$this->vie = $vie;
return $this;
}
public function getAttaque(): ?int
{
return $this->attaque;
}
public function setAttaque(int $attaque): self
{
$this->attaque = $attaque;
return $this;
}
public function getDefense(): ?int
{
return $this->defense;
}
public function setDefense(int $defense): self
{
$this->defense = $defense;
return $this;
}
public function getLegendaire(): ?bool
{
return $this->legendaire;
}
public function setLegendaire(bool $legendaire): self
{
$this->legendaire = $legendaire;
return $this;
}
public function getGeneration(): ?GenerationPoke
{
return $this->generation;
}
public function setGeneration(?GenerationPoke $generation): self
{
$this->generation = $generation;
return $this;
}
}

91
src/Entity/TypePoke.php

@ -0,0 +1,91 @@
<?php
namespace App\Entity;
use App\Repository\TypePokeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=TypePokeRepository::class)
* @ApiResource(
* normalizationContext={
* "groups"={"pokemon_read"}
* }
* )
*/
class TypePoke
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"pokemon_read"})
*/
private $name;
/**
* @ORM\OneToMany(targetEntity=Pokemon::class, mappedBy="type1")
*/
private $pokemon;
public function __construct()
{
$this->pokemon = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection|Pokemon[]
*/
public function getPokemon(): Collection
{
return $this->pokemon;
}
public function addPokemon(Pokemon $pokemon): self
{
if (!$this->pokemon->contains($pokemon)) {
$this->pokemon[] = $pokemon;
$pokemon->setType1($this);
}
return $this;
}
public function removePokemon(Pokemon $pokemon): self
{
if ($this->pokemon->removeElement($pokemon)) {
// set the owning side to null (unless already changed)
if ($pokemon->getType1() === $this) {
$pokemon->setType1(null);
}
}
return $this;
}
}

50
src/Repository/GenerationPokeRepository.php

@ -0,0 +1,50 @@
<?php
namespace App\Repository;
use App\Entity\GenerationPoke;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method GenerationPoke|null find($id, $lockMode = null, $lockVersion = null)
* @method GenerationPoke|null findOneBy(array $criteria, array $orderBy = null)
* @method GenerationPoke[] findAll()
* @method GenerationPoke[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class GenerationPokeRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, GenerationPoke::class);
}
// /**
// * @return GenerationPoke[] Returns an array of GenerationPoke objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('g')
->andWhere('g.exampleField = :val')
->setParameter('val', $value)
->orderBy('g.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?GenerationPoke
{
return $this->createQueryBuilder('g')
->andWhere('g.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}

50
src/Repository/PokemonRepository.php

@ -0,0 +1,50 @@
<?php
namespace App\Repository;
use App\Entity\Pokemon;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method Pokemon|null find($id, $lockMode = null, $lockVersion = null)
* @method Pokemon|null findOneBy(array $criteria, array $orderBy = null)
* @method Pokemon[] findAll()
* @method Pokemon[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class PokemonRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Pokemon::class);
}
// /**
// * @return Pokemon[] Returns an array of Pokemon objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('p')
->andWhere('p.exampleField = :val')
->setParameter('val', $value)
->orderBy('p.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?Pokemon
{
return $this->createQueryBuilder('p')
->andWhere('p.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}

50
src/Repository/TypePokeRepository.php

@ -0,0 +1,50 @@
<?php
namespace App\Repository;
use App\Entity\TypePoke;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method TypePoke|null find($id, $lockMode = null, $lockVersion = null)
* @method TypePoke|null findOneBy(array $criteria, array $orderBy = null)
* @method TypePoke[] findAll()
* @method TypePoke[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class TypePokeRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, TypePoke::class);
}
// /**
// * @return TypePoke[] Returns an array of TypePoke objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('t')
->andWhere('t.exampleField = :val')
->setParameter('val', $value)
->orderBy('t.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?TypePoke
{
return $this->createQueryBuilder('t')
->andWhere('t.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}

35
symfony.lock

@ -1,4 +1,21 @@
{
"api-platform/api-pack": {
"version": "v1.3.0"
},
"api-platform/core": {
"version": "2.5",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "2.5",
"ref": "a93061567140e386f107be75340ac2aee3f86cbf"
},
"files": [
"config/packages/api_platform.yaml",
"config/routes/api_platform.yaml",
"src/Entity/.gitignore"
]
},
"composer/package-versions-deprecated": {
"version": "1.11.99.1"
},
@ -82,6 +99,9 @@
"egulias/email-validator": {
"version": "3.1.0"
},
"fig/link-util": {
"version": "1.1.2"
},
"friendsofphp/proxy-manager-lts": {
"version": "v1.0.3"
},
@ -97,6 +117,18 @@
"monolog/monolog": {
"version": "2.2.0"
},
"nelmio/cors-bundle": {
"version": "1.5",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "1.5",
"ref": "6bea22e6c564fba3a1391615cada1437d0bde39c"
},
"files": [
"config/packages/nelmio_cors.yaml"
]
},
"nikic/php-parser": {
"version": "v4.10.4"
},
@ -517,5 +549,8 @@
},
"webmozart/assert": {
"version": "1.10.0"
},
"willdurand/negotiation": {
"version": "3.0.0"
}
}

Loading…
Cancel
Save