From 6d3586f1b31b50a609cf37993313bfb90bfc39e0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Jan 2025 05:50:56 +0000 Subject: [PATCH 1/2] build(deps-dev): bump friendsofphp/php-cs-fixer from 3.66.1 to 3.67.1 Bumps [friendsofphp/php-cs-fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) from 3.66.1 to 3.67.1. - [Release notes](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases) - [Changelog](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/CHANGELOG.md) - [Commits](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/compare/v3.66.1...v3.67.1) --- updated-dependencies: - dependency-name: friendsofphp/php-cs-fixer dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 0221d1f..ba9a20c 100644 --- a/composer.lock +++ b/composer.lock @@ -4823,16 +4823,16 @@ }, { "name": "friendsofphp/php-cs-fixer", - "version": "v3.66.1", + "version": "v3.67.1", "source": { "type": "git", "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", - "reference": "cde186799d8e92960c5a00c96e6214bf7f5547a9" + "reference": "db533e9aeb19c33033b6a1b734c8de4f4ebaa7dc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/cde186799d8e92960c5a00c96e6214bf7f5547a9", - "reference": "cde186799d8e92960c5a00c96e6214bf7f5547a9", + "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/db533e9aeb19c33033b6a1b734c8de4f4ebaa7dc", + "reference": "db533e9aeb19c33033b6a1b734c8de4f4ebaa7dc", "shasum": "" }, "require": { @@ -4914,7 +4914,7 @@ ], "support": { "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", - "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.66.1" + "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.67.1" }, "funding": [ { @@ -4922,7 +4922,7 @@ "type": "github" } ], - "time": "2025-01-05T14:43:25+00:00" + "time": "2025-01-12T12:20:47+00:00" }, { "name": "icecave/parity", From e8cdfef3a2f33e5ff5b6bc761600447426c6221a Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Tue, 14 Jan 2025 17:22:20 +0100 Subject: [PATCH 2/2] `/reports` : Add pagination (per default) --- src/Controller/ReportController.php | 12 ++++++++++-- src/Repository/ExecutionRepository.php | 23 +++++++++++++++++++++++ tests/Controller/ReportControllerTest.php | 7 +++++-- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index 5cfbc46..16a2573 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -38,6 +38,9 @@ public function reports(Request $request): JsonResponse { $executionFilters = []; $requestParams = $request->query->all(); + $paramPage = $requestParams['page'] ?? 1; + $paramLimit = $requestParams['limit'] ?? 20; + $paramLimit = $paramLimit > 100 ? 100 : $paramLimit; if (isset($requestParams['filter_platform'])) { $executionFilters['platform'] = $requestParams['filter_platform']; @@ -52,7 +55,9 @@ public function reports(Request $request): JsonResponse } $executions = $this->executionRepository->findBy($executionFilters, [ 'start_date' => 'DESC', - ]); + ], $paramLimit, ($paramPage - 1) * $paramLimit); + + $numExecutions = $this->executionRepository->count($executionFilters); $reportListing = []; if (!isset($executionFilters['platform']) && !isset($executionFilters['campaign'])) { @@ -108,7 +113,10 @@ public function reports(Request $request): JsonResponse return ($tm1 < $tm2) ? 1 : (($tm1 > $tm2) ? -1 : 0); }); - return new JsonResponse($reports); + $response = new JsonResponse(['count' => $numExecutions, 'reports' => $reports]); + $response->headers->set('Access-Control-Allow-Origin', '*'); + + return $response; } #[Route('/reports/{idReport}', methods: ['GET'])] diff --git a/src/Repository/ExecutionRepository.php b/src/Repository/ExecutionRepository.php index 5ce3692..5dd6789 100644 --- a/src/Repository/ExecutionRepository.php +++ b/src/Repository/ExecutionRepository.php @@ -124,4 +124,27 @@ public function findAllBetweenDates(string $version, string $startDate, string $ return $qb->getQuery()->getResult(); } + + public function count(array $criteria = []): int + { + $qb = $this->createQueryBuilder('e'); + $qb->select($qb->expr()->count('e')); + if (isset($criteria['platform'])) { + $qb + ->andWhere('e.platform = :platform') + ->setParameter('platform', $criteria['platform']); + } + if (isset($criteria['campaign'])) { + $qb + ->andWhere('e.campaign = :campaign') + ->setParameter('campaign', $criteria['campaign']); + } + if (isset($criteria['version'])) { + $qb + ->andWhere('e.version = :version') + ->setParameter('version', $criteria['version']); + } + + return $qb->getQuery()->getSingleScalarResult(); + } } diff --git a/tests/Controller/ReportControllerTest.php b/tests/Controller/ReportControllerTest.php index 39f936d..65561a7 100644 --- a/tests/Controller/ReportControllerTest.php +++ b/tests/Controller/ReportControllerTest.php @@ -55,9 +55,12 @@ public function testReportsFilters(array $query, int $count): void $this->assertEquals('application/json', $response->headers->get('content-type')); $content = json_decode($response->getContent(), true); - $this->assertEquals($count, count($content)); + $this->assertArrayHasKey('count', $content); + $this->assertGreaterThan(0, $content['count']); + $this->assertArrayHasKey('reports', $content); + $this->assertEquals($count, count($content['reports'])); $datePrevious = null; - foreach ($content as $item) { + foreach ($content['reports'] as $item) { if ($datePrevious) { $this->assertGreaterThanOrEqual($item['start_date'], $datePrevious); }