From f937d225ee4203e45749450d5d98da433e6d1893 Mon Sep 17 00:00:00 2001 From: Dosseh KOUTO Date: Thu, 2 Jan 2020 11:58:36 +0100 Subject: [PATCH 1/2] Finalisation de Entity --- api/composer.json | 2 + api/composer.lock | 203 ++++++++++++++++++++++++++++++++++++++++- api/config/bundles.php | 1 + api/symfony.lock | 18 ++++ 4 files changed, 223 insertions(+), 1 deletion(-) diff --git a/api/composer.json b/api/composer.json index 14450fc..2c6eb51 100644 --- a/api/composer.json +++ b/api/composer.json @@ -7,6 +7,7 @@ "api-platform/api-pack": "^1.1", "doctrine/doctrine-migrations-bundle": "^2.0", "guzzlehttp/guzzle": "^6.3", + "league/csv": "^9.5", "symfony/console": "4.3.*", "symfony/dotenv": "4.3.*", "symfony/flex": "^1.1", @@ -16,6 +17,7 @@ }, "require-dev": { "api-platform/schema-generator": "^2.1", + "doctrine/doctrine-fixtures-bundle": "^3.3", "symfony/maker-bundle": "^1.11", "symfony/profiler-pack": "^1.0" }, diff --git a/api/composer.lock b/api/composer.lock index 95f7e2d..ddd4dae 100644 --- a/api/composer.lock +++ b/api/composer.lock @@ -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": "d92d21009b99fe46500a17d5373db77a", + "content-hash": "43bcf85097aaba1b9f8d21cbff3de350", "packages": [ { "name": "api-platform/api-pack", @@ -1617,6 +1617,75 @@ ], "time": "2014-01-12T16:20:24+00:00" }, + { + "name": "league/csv", + "version": "9.5.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/csv.git", + "reference": "b348d09d0d258a4f068efb50a2510dc63101c213" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/csv/zipball/b348d09d0d258a4f068efb50a2510dc63101c213", + "reference": "b348d09d0d258a4f068efb50a2510dc63101c213", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-mbstring": "*", + "php": ">=7.0.10" + }, + "require-dev": { + "ext-curl": "*", + "friendsofphp/php-cs-fixer": "^2.12", + "phpstan/phpstan": "^0.9.2", + "phpstan/phpstan-phpunit": "^0.9.4", + "phpstan/phpstan-strict-rules": "^0.9.0", + "phpunit/phpunit": "^6.0" + }, + "suggest": { + "ext-iconv": "Needed to ease transcoding CSV using iconv stream filters" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "9.x-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Csv\\": "src" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ignace Nyamagana Butera", + "email": "nyamsprod@gmail.com", + "homepage": "https://github.com/nyamsprod/", + "role": "Developer" + } + ], + "description": "Csv data manipulation made easy in PHP", + "homepage": "http://csv.thephpleague.com", + "keywords": [ + "csv", + "export", + "filter", + "import", + "read", + "write" + ], + "time": "2019-12-15T19:51:41+00:00" + }, { "name": "nelmio/cors-bundle", "version": "2.0.1", @@ -5508,6 +5577,7 @@ "code", "zf" ], + "abandoned": "laminas/laminas-code", "time": "2019-10-05T23:18:22+00:00" }, { @@ -5562,6 +5632,7 @@ "events", "zf2" ], + "abandoned": "laminas/laminas-eventmanager", "time": "2018-04-25T15:33:34+00:00" } ], @@ -5740,6 +5811,136 @@ ], "time": "2019-11-06T16:40:04+00:00" }, + { + "name": "doctrine/data-fixtures", + "version": "1.4.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/data-fixtures.git", + "reference": "608a35a3b5bcc4214d116603095f8b0c51091592" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/data-fixtures/zipball/608a35a3b5bcc4214d116603095f8b0c51091592", + "reference": "608a35a3b5bcc4214d116603095f8b0c51091592", + "shasum": "" + }, + "require": { + "doctrine/common": "^2.11", + "php": "^7.2" + }, + "conflict": { + "doctrine/phpcr-odm": "<1.3.0" + }, + "require-dev": { + "alcaeus/mongo-php-adapter": "^1.1", + "doctrine/coding-standard": "^6.0", + "doctrine/dbal": "^2.5.4", + "doctrine/mongodb-odm": "^1.3.0", + "doctrine/orm": "^2.5.4", + "phpunit/phpunit": "^7.0" + }, + "suggest": { + "alcaeus/mongo-php-adapter": "For using MongoDB ODM with PHP 7", + "doctrine/mongodb-odm": "For loading MongoDB ODM fixtures", + "doctrine/orm": "For loading ORM fixtures", + "doctrine/phpcr-odm": "For loading PHPCR ODM fixtures" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\DataFixtures\\": "lib/Doctrine/Common/DataFixtures" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + } + ], + "description": "Data Fixtures for all Doctrine Object Managers", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "database" + ], + "time": "2019-10-30T20:03:18+00:00" + }, + { + "name": "doctrine/doctrine-fixtures-bundle", + "version": "3.3.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/DoctrineFixturesBundle.git", + "reference": "8f07fcfdac7f3591f3c4bf13a50cbae05f65ed70" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/DoctrineFixturesBundle/zipball/8f07fcfdac7f3591f3c4bf13a50cbae05f65ed70", + "reference": "8f07fcfdac7f3591f3c4bf13a50cbae05f65ed70", + "shasum": "" + }, + "require": { + "doctrine/data-fixtures": "^1.3", + "doctrine/doctrine-bundle": "^1.11|^2.0", + "doctrine/orm": "^2.6.0", + "php": "^7.1", + "symfony/config": "^3.4|^4.3|^5.0", + "symfony/console": "^3.4|^4.3|^5.0", + "symfony/dependency-injection": "^3.4|^4.3|^5.0", + "symfony/doctrine-bridge": "^3.4|^4.1|^5.0", + "symfony/http-kernel": "^3.4|^4.3|^5.0" + }, + "require-dev": { + "doctrine/coding-standard": "^6.0", + "phpunit/phpunit": "^7.4", + "symfony/phpunit-bridge": "^4.1|^5.0" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "3.3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Bundle\\FixturesBundle\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Doctrine Project", + "homepage": "http://www.doctrine-project.org" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony DoctrineFixturesBundle", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "Fixture", + "persistence" + ], + "time": "2019-11-13T15:46:58+00:00" + }, { "name": "easyrdf/easyrdf", "version": "0.9.1", diff --git a/api/config/bundles.php b/api/config/bundles.php index 0d1cb31..0815847 100644 --- a/api/config/bundles.php +++ b/api/config/bundles.php @@ -11,4 +11,5 @@ return [ Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], + Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true], ]; diff --git a/api/symfony.lock b/api/symfony.lock index bea0a66..40776b0 100644 --- a/api/symfony.lock +++ b/api/symfony.lock @@ -46,6 +46,9 @@ "doctrine/common": { "version": "v2.11.0" }, + "doctrine/data-fixtures": { + "version": "1.4.0" + }, "doctrine/dbal": { "version": "v2.10.0" }, @@ -67,6 +70,18 @@ "doctrine/doctrine-cache-bundle": { "version": "1.3.5" }, + "doctrine/doctrine-fixtures-bundle": { + "version": "3.0", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "3.0", + "ref": "fc52d86631a6dfd9fdf3381d0b7e3df2069e51b3" + }, + "files": [ + "src/DataFixtures/AppFixtures.php" + ] + }, "doctrine/doctrine-migrations-bundle": { "version": "1.2", "recipe": { @@ -134,6 +149,9 @@ "jdorn/sql-formatter": { "version": "v1.2.17" }, + "league/csv": { + "version": "9.5.0" + }, "league/html-to-markdown": { "version": "4.9.0" }, -- GitLab From ab97942ee235d537d1af8b5a5bc2e3a1bd628978 Mon Sep 17 00:00:00 2001 From: Dosseh KOUTO Date: Thu, 2 Jan 2020 14:24:25 +0100 Subject: [PATCH 2/2] =?UTF-8?q?l'entit=C3=A9=20Valeurs=20Fonciere=20Termin?= =?UTF-8?q?er?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/composer.json | 1 + api/composer.lock | 58 ++++++++++++++++++++++ api/config/packages/doctrine.yaml | 3 ++ api/src/Controller/PrixMoyenParAnnee.php | 62 ++++++++++++++++++++++++ api/src/Entity/ValeursFonciere.php | 42 +++++++++++++++- api/symfony.lock | 3 ++ 6 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 api/src/Controller/PrixMoyenParAnnee.php diff --git a/api/composer.json b/api/composer.json index 2c6eb51..97ff106 100644 --- a/api/composer.json +++ b/api/composer.json @@ -5,6 +5,7 @@ "ext-ctype": "*", "ext-iconv": "*", "api-platform/api-pack": "^1.1", + "beberlei/doctrineextensions": "^1.2", "doctrine/doctrine-migrations-bundle": "^2.0", "guzzlehttp/guzzle": "^6.3", "league/csv": "^9.5", diff --git a/api/composer.lock b/api/composer.lock index ddd4dae..06e0cca 100644 --- a/api/composer.lock +++ b/api/composer.lock @@ -4,7 +4,11 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], +<<<<<<< HEAD "content-hash": "43bcf85097aaba1b9f8d21cbff3de350", +======= + "content-hash": "02cef2253a3de1d466f7aa78b7693e7b", +>>>>>>> 00b8e81310922d8f1b1eede38f2d1218ab9ebe46 "packages": [ { "name": "api-platform/api-pack", @@ -190,6 +194,60 @@ ], "time": "2019-11-23T11:27:39+00:00" }, + { + "name": "beberlei/doctrineextensions", + "version": "v1.2.6", + "source": { + "type": "git", + "url": "https://github.com/beberlei/DoctrineExtensions.git", + "reference": "af72c4a136b744f1268ca8bb4da47a2f8af78f86" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/beberlei/DoctrineExtensions/zipball/af72c4a136b744f1268ca8bb4da47a2f8af78f86", + "reference": "af72c4a136b744f1268ca8bb4da47a2f8af78f86", + "shasum": "" + }, + "require": { + "doctrine/orm": "^2.6", + "php": "^7.1" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.14", + "nesbot/carbon": "*", + "phpunit/phpunit": "^7.0 || ^8.0", + "symfony/yaml": "^4.2", + "zf1/zend-date": "^1.12", + "zf1/zend-registry": "^1.12" + }, + "type": "library", + "autoload": { + "psr-4": { + "DoctrineExtensions\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Steve Lacey", + "email": "steve@stevelacey.net" + } + ], + "description": "A set of extensions to Doctrine 2 that add support for additional query functions available in MySQL and Oracle.", + "keywords": [ + "database", + "doctrine", + "orm" + ], + "time": "2019-12-05T09:49:04+00:00" + }, { "name": "doctrine/annotations", "version": "v1.8.0", diff --git a/api/config/packages/doctrine.yaml b/api/config/packages/doctrine.yaml index 66d671f..7e6c080 100644 --- a/api/config/packages/doctrine.yaml +++ b/api/config/packages/doctrine.yaml @@ -17,3 +17,6 @@ doctrine: dir: '%kernel.project_dir%/src/Entity' prefix: 'App\Entity' alias: App + dql: + string_functions: + TO_CHAR: DoctrineExtensions\Query\Postgresql\DateFormat diff --git a/api/src/Controller/PrixMoyenParAnnee.php b/api/src/Controller/PrixMoyenParAnnee.php new file mode 100644 index 0000000..e15eaa6 --- /dev/null +++ b/api/src/Controller/PrixMoyenParAnnee.php @@ -0,0 +1,62 @@ +em = $em; + } + public function __invoke(Request $request) { + + $query = " SELECT + TO_CHAR(valeurs_fonciere.date_mutation, 'YYYY') AS annee, + TO_CHAR(valeurs_fonciere.date_mutation, 'MM') AS mois, + AVG(valeurs_fonciere.valeur_fonciere / valeurs_fonciere.surface_reelle_bati) AS prix_moyen_m_carree + FROM + App:ValeursFonciere AS valeurs_fonciere + WHERE + valeurs_fonciere.surface_reelle_bati > 0 + AND + valeurs_fonciere.valeur_fonciere > 0 + AND + lower(valeurs_fonciere.nature_mutation) = 'vente' + GROUP BY + annee, + mois + ORDER BY + annee, + mois"; + $prix_mettres = $this->em->createQuery($query)->getResult(); + foreach ($prix_mettres as &$prix_mettre){ + $prix_mettre['annee'] = intval($prix_mettre['annee']); + $prix_mettre['mois'] = intval($prix_mettre['mois']); + $prix_mettre['prix_moyen_m_carree'] = floatval($prix_mettre['prix_moyen_m_carree']); + } + $res = new JsonResponse( + $prix_mettres, + Response::HTTP_OK + ); + return $res; + } +} \ No newline at end of file diff --git a/api/src/Entity/ValeursFonciere.php b/api/src/Entity/ValeursFonciere.php index 2807013..eddb08b 100644 --- a/api/src/Entity/ValeursFonciere.php +++ b/api/src/Entity/ValeursFonciere.php @@ -6,7 +6,47 @@ use ApiPlatform\Core\Annotation\ApiResource; use Doctrine\ORM\Mapping as ORM; /** - * @ApiResource() + * @ApiResource(collectionOperations={ + * "get", + * "prixmoyens"={ + * "method"="GET", + * "openapi_context"={ + * "summary"="Obtient la moyenne du prix du mètre carré pour l'année et le mois sélectionnés", + * "produces"={ + * "application/json" + * }, + * "responses"={ + * "200"={ + * "description"="Moyenne du prix au mètre carré", + * "content"= { + * "application/json"={ + * "schema"={ + * "type"="array", + * "items"={ + * "type"="object", + * "properties"={ + * "annee"={ + * "type"="number" + * }, + * "mois"={ + * "type"="number" + * }, + * "prix_moyen_m_carree"={ + * "type"="number" + * } + * } + * } + * } + * } + * } + * } + * } + * }, + * "route_name"="prix_moyens", + * "controller"=PrixMoyenParAnnee::class, + * "pagination_enabled"=false, + * } + * }) * @ORM\Entity(repositoryClass="App\Repository\ValeursFonciereRepository") */ class ValeursFonciere diff --git a/api/symfony.lock b/api/symfony.lock index 40776b0..66c7764 100644 --- a/api/symfony.lock +++ b/api/symfony.lock @@ -19,6 +19,9 @@ "api-platform/schema-generator": { "version": "v2.1.0" }, + "beberlei/doctrineextensions": { + "version": "v1.2.6" + }, "composer/semver": { "version": "1.5.0" }, -- GitLab