Add location_code filter to streams endpoint for live camera filtering

This commit is contained in:
mwpn
2025-12-17 17:57:14 +07:00
parent d2b4def127
commit 1d5511ccbc
2 changed files with 16 additions and 6 deletions

View File

@@ -121,23 +121,25 @@ class RetribusiReadService
* *
* @param int $page * @param int $page
* @param int $limit * @param int $limit
* @param string|null $locationCode Optional filter by location
* @return array * @return array
* @throws PDOException * @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) // Sementara stream = gate (alias)
return $this->getGates($page, $limit); return $this->getGates($page, $limit, $locationCode);
} }
/** /**
* Get total count of streams * Get total count of streams
* *
* @param string|null $locationCode Optional filter by location
* @return int * @return int
* @throws PDOException * @throws PDOException
*/ */
public function getStreamsTotal(): int public function getStreamsTotal(?string $locationCode = null): int
{ {
return $this->getGatesTotal(); return $this->getGatesTotal($locationCode);
} }
} }

View File

@@ -25,8 +25,16 @@ class StreamController
$queryParams = $request->getQueryParams(); $queryParams = $request->getQueryParams();
[$page, $limit] = Validator::validatePagination($queryParams); [$page, $limit] = Validator::validatePagination($queryParams);
$data = $this->service->getStreams($page, $limit); // Get location_code filter
$total = $this->service->getStreamsTotal(); $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( return ResponseHelper::json(
$response, $response,