From 440590ee512f9d4214334d870ca21dc2f39235a2 Mon Sep 17 00:00:00 2001 From: ivar Date: Mon, 20 Oct 2025 00:32:22 +0200 Subject: refactor: Parse inputs to double in parameter --- api/.idea/.idea.WhatApi/.idea/.name | 1 + api/.idea/.idea.WhatApi/.idea/vcs.xml | 6 ++++++ api/WhatApi/Endpoints/GetPlacesEndpoint.cs | 13 ++++--------- 3 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 api/.idea/.idea.WhatApi/.idea/.name create mode 100644 api/.idea/.idea.WhatApi/.idea/vcs.xml diff --git a/api/.idea/.idea.WhatApi/.idea/.name b/api/.idea/.idea.WhatApi/.idea/.name new file mode 100644 index 0000000..d9940ce --- /dev/null +++ b/api/.idea/.idea.WhatApi/.idea/.name @@ -0,0 +1 @@ +WhatApi \ No newline at end of file diff --git a/api/.idea/.idea.WhatApi/.idea/vcs.xml b/api/.idea/.idea.WhatApi/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/api/.idea/.idea.WhatApi/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/api/WhatApi/Endpoints/GetPlacesEndpoint.cs b/api/WhatApi/Endpoints/GetPlacesEndpoint.cs index 5630229..a3fc7e3 100644 --- a/api/WhatApi/Endpoints/GetPlacesEndpoint.cs +++ b/api/WhatApi/Endpoints/GetPlacesEndpoint.cs @@ -10,21 +10,16 @@ namespace WhatApi.Endpoints; public class GetPlacesEndpoint(Database db) : BaseEndpoint { [HttpGet("~/places")] - public async Task HandleAsync(string w, string s, string e, string n, CancellationToken ct = default) { - var north = double.Parse(n); - var east = double.Parse(e); - var south = double.Parse(s); - var west = double.Parse(w); - + public async Task HandleAsync(double w, double s, double e, double n, CancellationToken ct = default) { IQueryable resultingQuery; - if (west > east) { + if (w > e) { resultingQuery = db.Places .FromSqlInterpolated($""" SELECT * FROM "Place" WHERE ST_Intersects( "Location", - ST_MakeEnvelope({west}, {south}, 180, {north}, {Constants.Wgs84SpatialReferenceId}) || ST_MakeEnvelope(-180, {south}, {east}, {north}, {Constants.Wgs84SpatialReferenceId}) + ST_MakeEnvelope({w}, {s}, 180, {n}, {Constants.Wgs84SpatialReferenceId}) || ST_MakeEnvelope(-180, {n}, {e}, {n}, {Constants.Wgs84SpatialReferenceId}) ) """); } else { @@ -33,7 +28,7 @@ public class GetPlacesEndpoint(Database db) : BaseEndpoint SELECT * FROM "Place" WHERE ST_Intersects( "Location", - ST_MakeEnvelope({west}, {south}, {east}, {north}, {Constants.Wgs84SpatialReferenceId}) + ST_MakeEnvelope({w}, {s}, {e}, {n}, {Constants.Wgs84SpatialReferenceId}) ) """); } -- cgit v1.3