From 1d5511ccbc831df00006ad3daf2736912fbc7644 Mon Sep 17 00:00:00 2001 From: mwpn Date: Wed, 17 Dec 2025 17:57:14 +0700 Subject: [PATCH] Add location_code filter to streams endpoint for live camera filtering --- .../Retribusi/Frontend/RetribusiReadService.php | 10 ++++++---- src/Modules/Retribusi/Frontend/StreamController.php | 12 ++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Modules/Retribusi/Frontend/RetribusiReadService.php b/src/Modules/Retribusi/Frontend/RetribusiReadService.php index 7131693..5c8123d 100644 --- a/src/Modules/Retribusi/Frontend/RetribusiReadService.php +++ b/src/Modules/Retribusi/Frontend/RetribusiReadService.php @@ -121,23 +121,25 @@ class RetribusiReadService * * @param int $page * @param int $limit + * @param string|null $locationCode Optional filter by location * @return array * @throws PDOException */ - public function getStreams(int $page, int $limit): array + public function getStreams(int $page, int $limit, ?string $locationCode = null): array { // Sementara stream = gate (alias) - return $this->getGates($page, $limit); + return $this->getGates($page, $limit, $locationCode); } /** * Get total count of streams * + * @param string|null $locationCode Optional filter by location * @return int * @throws PDOException */ - public function getStreamsTotal(): int + public function getStreamsTotal(?string $locationCode = null): int { - return $this->getGatesTotal(); + return $this->getGatesTotal($locationCode); } } diff --git a/src/Modules/Retribusi/Frontend/StreamController.php b/src/Modules/Retribusi/Frontend/StreamController.php index e4ab433..f3723c0 100644 --- a/src/Modules/Retribusi/Frontend/StreamController.php +++ b/src/Modules/Retribusi/Frontend/StreamController.php @@ -25,8 +25,16 @@ class StreamController $queryParams = $request->getQueryParams(); [$page, $limit] = Validator::validatePagination($queryParams); - $data = $this->service->getStreams($page, $limit); - $total = $this->service->getStreamsTotal(); + // Get location_code filter + $locationCode = $queryParams['location_code'] ?? null; + if ($locationCode !== null && (!is_string($locationCode) || trim($locationCode) === '')) { + $locationCode = null; + } else if ($locationCode !== null) { + $locationCode = trim($locationCode); + } + + $data = $this->service->getStreams($page, $limit, $locationCode); + $total = $this->service->getStreamsTotal($locationCode); return ResponseHelper::json( $response,