From 53752b62dad501ff908266594a6613f1a3b4b3b1 Mon Sep 17 00:00:00 2001 From: Ibrahima Sow Date: Mon, 2 Jan 2023 23:00:25 +0100 Subject: [PATCH] feat: implementation BarChartController et DonutChartController --- .../src/Controller/Api/BarChartController.php | 28 ++++++++++++++- .../Controller/Api/DonutChartController.php | 34 +++++++++++++++++++ .../Controller/Api/LineChartController.php | 16 +++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 Back-End/src/Controller/Api/DonutChartController.php create mode 100644 Back-End/src/Controller/Api/LineChartController.php diff --git a/Back-End/src/Controller/Api/BarChartController.php b/Back-End/src/Controller/Api/BarChartController.php index 5a958a06..a1df496a 100644 --- a/Back-End/src/Controller/Api/BarChartController.php +++ b/Back-End/src/Controller/Api/BarChartController.php @@ -2,4 +2,30 @@ namespace App\Controller\Api; -} +use App\Entity\LandValue; +use App\Repository\LandValueRepository; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\Routing\Annotation\Route; + +class BarChartController extends AbstractController +{ + private LandValueRepository $landValueRepository; + private Request $request; + + public function __construct(LandValueRepository $landValueRepository, RequestStack $request) + { + $this->landValueRepository = $landValueRepository; + $this->request = $request->getCurrentRequest(); + } + + public function __invoke(): array + { + $startParam = $this->request->query->get('start'); + $endParam = $this->request->query->get('end'); + $groupParam = $this->request->query->get('group'); + + return $this->landValueRepository->barChart($startParam, $endParam, $groupParam); + } +} \ No newline at end of file diff --git a/Back-End/src/Controller/Api/DonutChartController.php b/Back-End/src/Controller/Api/DonutChartController.php new file mode 100644 index 00000000..b7c1a1e2 --- /dev/null +++ b/Back-End/src/Controller/Api/DonutChartController.php @@ -0,0 +1,34 @@ +landValueRepository = $landValueRepository; + $this->request = $request->getCurrentRequest(); + } + + public function __invoke(): array + { + $year = $this->request->query->get('year'); + + if ($year === null) { + $year = '2022'; + } + + return $this->landValueRepository->donutChart($year); + } +} diff --git a/Back-End/src/Controller/Api/LineChartController.php b/Back-End/src/Controller/Api/LineChartController.php new file mode 100644 index 00000000..c08a2e79 --- /dev/null +++ b/Back-End/src/Controller/Api/LineChartController.php @@ -0,0 +1,16 @@ +