From a041aaa4b23a700540f5fc13139877c115e5bd7d Mon Sep 17 00:00:00 2001 From: Hugman Date: Wed, 11 Feb 2026 12:21:04 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20des=20routes=20n=C3=A9cessaires=20pour?= =?UTF-8?q?=20chaque=20diagramme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/src/ApiResource/AverageTaxStats.php | 59 +++++++++++++++ .../api/src/ApiResource/RegionVolumeStats.php | 56 ++++++++++++++ api-platform/api/src/Entity/Commune.php | 9 ++- api-platform/api/src/Entity/Departement.php | 9 ++- api-platform/api/src/Entity/Region.php | 9 ++- api-platform/api/src/Entity/Taxe.php | 20 ++++- api-platform/api/src/Entity/TypeTaxe.php | 9 ++- .../api/src/Repository/TaxeRepository.php | 75 +++++++++++++------ .../api/src/State/AverageTaxStatsProvider.php | 38 ++++++++++ .../src/State/RegionVolumeStatsProvider.php | 36 +++++++++ 10 files changed, 292 insertions(+), 28 deletions(-) create mode 100644 api-platform/api/src/ApiResource/AverageTaxStats.php create mode 100644 api-platform/api/src/ApiResource/RegionVolumeStats.php create mode 100644 api-platform/api/src/State/AverageTaxStatsProvider.php create mode 100644 api-platform/api/src/State/RegionVolumeStatsProvider.php diff --git a/api-platform/api/src/ApiResource/AverageTaxStats.php b/api-platform/api/src/ApiResource/AverageTaxStats.php new file mode 100644 index 0000000..859d973 --- /dev/null +++ b/api-platform/api/src/ApiResource/AverageTaxStats.php @@ -0,0 +1,59 @@ + 'integer'] + ), + new Parameter( + name: 'endYear', + in: 'query', + description: 'Année de fin', + required: true, + schema: ['type' => 'integer'] + ), + new Parameter( + name: 'typeCode', + in: 'query', + description: 'Code du type de taxe (ex: TFPNB, TH...)', + required: true, + schema: ['type' => 'string'] + ), + ] + ), + provider: AverageTaxStatsProvider::class + ) + ], + paginationEnabled: false +)] +class AverageTaxStats +{ + #[ApiProperty(identifier: true)] + public string $id; + + public function __construct( + public string $region, + public int $annee, + public float $tauxMoyen + ) { + $this->id = $region . '-' . $annee; + } +} diff --git a/api-platform/api/src/ApiResource/RegionVolumeStats.php b/api-platform/api/src/ApiResource/RegionVolumeStats.php new file mode 100644 index 0000000..0c00746 --- /dev/null +++ b/api-platform/api/src/ApiResource/RegionVolumeStats.php @@ -0,0 +1,56 @@ + 'integer'] + ), + new Parameter( + name: 'typeCode', + in: 'query', + description: 'Code du type de taxe (ex: TFPNB, TH...)', + required: true, + schema: ['type' => 'string'] + ), + ] + ), + provider: RegionVolumeStatsProvider::class + ) + ], + paginationEnabled: false +)] +class RegionVolumeStats +{ + #[ApiProperty(identifier: true)] + public string $id; + + public string $region; + + public float $totalVolume; + + public function __construct(string $region, float $totalVolume) + { + $this->region = $region; + $this->totalVolume = $totalVolume; + $this->id = sprintf('%s-%s', $region, uniqid()); + } +} + diff --git a/api-platform/api/src/Entity/Commune.php b/api-platform/api/src/Entity/Commune.php index 666bc3f..384a105 100644 --- a/api-platform/api/src/Entity/Commune.php +++ b/api-platform/api/src/Entity/Commune.php @@ -3,13 +3,20 @@ namespace App\Entity; use ApiPlatform\Metadata\ApiResource; +use ApiPlatform\Metadata\Get; +use ApiPlatform\Metadata\GetCollection; use App\Repository\CommuneRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: CommuneRepository::class)] -#[ApiResource] +#[ApiResource( + operations: [ + new Get(), + new GetCollection() + ] +)] class Commune { #[ORM\Id] diff --git a/api-platform/api/src/Entity/Departement.php b/api-platform/api/src/Entity/Departement.php index dd61c5f..3e83636 100644 --- a/api-platform/api/src/Entity/Departement.php +++ b/api-platform/api/src/Entity/Departement.php @@ -3,13 +3,20 @@ namespace App\Entity; use ApiPlatform\Metadata\ApiResource; +use ApiPlatform\Metadata\Get; +use ApiPlatform\Metadata\GetCollection; use App\Repository\DepartementRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: DepartementRepository::class)] -#[ApiResource] +#[ApiResource( + operations: [ + new Get(), + new GetCollection() + ] +)] class Departement { #[ORM\Id] diff --git a/api-platform/api/src/Entity/Region.php b/api-platform/api/src/Entity/Region.php index 617cb3a..95ba0d7 100644 --- a/api-platform/api/src/Entity/Region.php +++ b/api-platform/api/src/Entity/Region.php @@ -3,13 +3,20 @@ namespace App\Entity; use ApiPlatform\Metadata\ApiResource; +use ApiPlatform\Metadata\Get; +use ApiPlatform\Metadata\GetCollection; use App\Repository\RegionRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: RegionRepository::class)] -#[ApiResource] +#[ApiResource( + operations: [ + new Get(), + new GetCollection() + ] +)] class Region { #[ORM\Id] diff --git a/api-platform/api/src/Entity/Taxe.php b/api-platform/api/src/Entity/Taxe.php index bba17e4..d3fd048 100644 --- a/api-platform/api/src/Entity/Taxe.php +++ b/api-platform/api/src/Entity/Taxe.php @@ -3,11 +3,29 @@ namespace App\Entity; use ApiPlatform\Metadata\ApiResource; +use ApiPlatform\Metadata\ApiFilter; +use ApiPlatform\Metadata\Get; +use ApiPlatform\Metadata\GetCollection; +use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; +use ApiPlatform\Doctrine\Orm\Filter\RangeFilter; use App\Repository\TaxeRepository; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: TaxeRepository::class)] -#[ApiResource] +#[ApiResource( + operations: [ + new Get(), + new GetCollection() + ], + paginationClientEnabled: true +)] +#[ApiFilter(SearchFilter::class, properties: [ + 'type' => 'exact', + 'type.code' => 'exact', + 'annee' => 'exact', + 'commune.departement' => 'exact' +])] +#[ApiFilter(RangeFilter::class, properties: ['annee'])] class Taxe { #[ORM\Id] diff --git a/api-platform/api/src/Entity/TypeTaxe.php b/api-platform/api/src/Entity/TypeTaxe.php index 03f76a3..91ff8fe 100644 --- a/api-platform/api/src/Entity/TypeTaxe.php +++ b/api-platform/api/src/Entity/TypeTaxe.php @@ -3,13 +3,20 @@ namespace App\Entity; use ApiPlatform\Metadata\ApiResource; +use ApiPlatform\Metadata\Get; +use ApiPlatform\Metadata\GetCollection; use App\Repository\TypeTaxeRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: TypeTaxeRepository::class)] -#[ApiResource] +#[ApiResource( + operations: [ + new Get(), + new GetCollection() + ] +)] class TypeTaxe { public const TFPNB_CODE = 'TFPNB'; diff --git a/api-platform/api/src/Repository/TaxeRepository.php b/api-platform/api/src/Repository/TaxeRepository.php index 9218441..d47c890 100644 --- a/api-platform/api/src/Repository/TaxeRepository.php +++ b/api-platform/api/src/Repository/TaxeRepository.php @@ -16,28 +16,57 @@ class TaxeRepository extends ServiceEntityRepository parent::__construct($registry, Taxe::class); } -// /** -// * @return Taxe[] Returns an array of Taxe objects -// */ -// public function findByExampleField($value): array -// { -// return $this->createQueryBuilder('t') -// ->andWhere('t.exampleField = :val') -// ->setParameter('val', $value) -// ->orderBy('t.id', 'ASC') -// ->setMaxResults(10) -// ->getQuery() -// ->getResult() -// ; -// } + /** + * Récupère les taux moyens par région pour une plage d'années et un type de taxe. + * + * @param int $startYear + * @param int $endYear + * @param string $typeCode + * @return array + */ + public function findAverageTauxByRegion(int $startYear, int $endYear, string $typeCode): array + { + return $this->createQueryBuilder('t') + ->select('r.nom as region', 't.annee', 'AVG(t.taux) as tauxMoyen') + ->join('t.commune', 'c') + ->join('c.departement', 'd') + ->join('d.region', 'r') + ->join('t.type', 'typeTaxe') + ->where('t.annee >= :start') + ->andWhere('t.annee <= :end') + ->andWhere('typeTaxe.code = :typeCode') + ->groupBy('r.nom', 't.annee') + ->orderBy('t.annee', 'ASC') + ->addOrderBy('r.nom', 'ASC') + ->setParameter('start', $startYear) + ->setParameter('end', $endYear) + ->setParameter('typeCode', $typeCode) + ->getQuery() + ->getResult(); + } -// public function findOneBySomeField($value): ?Taxe -// { -// return $this->createQueryBuilder('t') -// ->andWhere('t.exampleField = :val') -// ->setParameter('val', $value) -// ->getQuery() -// ->getOneOrNullResult() -// ; -// } + /** + * Récupère la somme des volumes par région pour une année et un type de taxe. + * + * @param int $annee + * @param string $typeCode + * @return array + */ + public function findVolumesByRegion(int $annee, string $typeCode): array + { + return $this->createQueryBuilder('t') + ->select('r.nom as region', 'SUM(t.volume) as totalVolume') + ->join('t.commune', 'c') + ->join('c.departement', 'd') + ->join('d.region', 'r') + ->join('t.type', 'typeTaxe') + ->where('t.annee = :annee') + ->andWhere('typeTaxe.code = :typeCode') + ->groupBy('r.nom') + ->orderBy('totalVolume', 'DESC') + ->setParameter('annee', $annee) + ->setParameter('typeCode', $typeCode) + ->getQuery() + ->getResult(); + } } diff --git a/api-platform/api/src/State/AverageTaxStatsProvider.php b/api-platform/api/src/State/AverageTaxStatsProvider.php new file mode 100644 index 0000000..78c8b94 --- /dev/null +++ b/api-platform/api/src/State/AverageTaxStatsProvider.php @@ -0,0 +1,38 @@ +taxeRepository->findAverageTauxByRegion($startYear, $endYear, $typeCode); + + $dtos = []; + foreach ($results as $result) { + $dtos[] = new AverageTaxStats( + $result['region'], + $result['annee'], + (float)$result['tauxMoyen'] + ); + } + + return $dtos; + } +} + diff --git a/api-platform/api/src/State/RegionVolumeStatsProvider.php b/api-platform/api/src/State/RegionVolumeStatsProvider.php new file mode 100644 index 0000000..5fcadf1 --- /dev/null +++ b/api-platform/api/src/State/RegionVolumeStatsProvider.php @@ -0,0 +1,36 @@ +taxeRepository->findVolumesByRegion($year, $typeCode); + + $dtos = []; + foreach ($results as $result) { + $dtos[] = new RegionVolumeStats( + $result['region'], + (float)$result['totalVolume'] + ); + } + + return $dtos; + } +} + -- GitLab