fix empty get

This commit is contained in:
2025-12-10 02:49:07 +00:00
parent 5e7d2f9a77
commit dfb2a3ba6e

View File

@@ -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,
@@ -19,16 +19,16 @@ if (empty($_GET)) {
'county', county,
'state', state,
'outage', outagen,
'lastchange', last_change,
'cause', cause,
'lastchange', last_change,
'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()]);
}
}