Add location_code filter to streams endpoint for live camera filtering
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user