From dfb2a3ba6e343762d7b7a19c9cbadbec10daa7d8 Mon Sep 17 00:00:00 2001 From: John Peck Date: Wed, 10 Dec 2025 02:49:07 +0000 Subject: [PATCH] fix empty get --- php/newpowerapi.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/php/newpowerapi.php b/php/newpowerapi.php index dd56c2a..10270fc 100644 --- a/php/newpowerapi.php +++ b/php/newpowerapi.php @@ -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()]); } }