fix empty get
This commit is contained in:
@@ -5,12 +5,12 @@ header('Content-Type: application/json');
|
||||
$dbconn = getDBConnection();
|
||||
|
||||
// Default endpoint: Get current point outages
|
||||
if (empty($_GET)) {
|
||||
if (empty(array_diff_key($_GET, array('service' => '')))) {
|
||||
try {
|
||||
$query = "
|
||||
SELECT json_build_object(
|
||||
'type', 'FeatureCollection',
|
||||
'features', json_agg(
|
||||
'features', COALESCE(json_agg(
|
||||
json_build_object(
|
||||
'type', 'Feature',
|
||||
'geometry', ST_AsGeoJSON(geom)::json,
|
||||
@@ -20,15 +20,15 @@ if (empty($_GET)) {
|
||||
'state', state,
|
||||
'outage', outagen,
|
||||
'lastchange', last_change,
|
||||
'cause', cause,
|
||||
'cause', COALESCE(cause, ''),
|
||||
'area_geometry', ST_AsGeoJSON(COALESCE(realareageom, geom))::json
|
||||
)
|
||||
)
|
||||
ORDER BY start_time ASC
|
||||
)
|
||||
), '[]'::json)
|
||||
) as geojson
|
||||
FROM newpower
|
||||
WHERE cwa = $1 AND active = true
|
||||
WHERE cwa = $1 AND active = true AND geom IS NOT NULL
|
||||
";
|
||||
|
||||
$result = pg_query_params($dbconn, $query, array('RLX'));
|
||||
@@ -47,7 +47,7 @@ if (empty($_GET)) {
|
||||
pg_free_result($result);
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
die(json_encode(['error' => 'Query execution failed: ' . $e->getMessage()]));
|
||||
echo json_encode(['error' => 'Query execution failed: ' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user