diff options
| author | ivar <i@oiee.no> | 2025-10-20 00:32:22 +0200 |
|---|---|---|
| committer | ivar <i@oiee.no> | 2025-10-20 00:32:22 +0200 |
| commit | 440590ee512f9d4214334d870ca21dc2f39235a2 (patch) | |
| tree | 1720a7f54e15fe3cf207ca48de57cf265567635b /api/WhatApi/Endpoints/GetPlacesEndpoint.cs | |
| parent | a1f0518d0cd123a791adde64f4f11bd8e44276c7 (diff) | |
| download | what-440590ee512f9d4214334d870ca21dc2f39235a2.tar.xz what-440590ee512f9d4214334d870ca21dc2f39235a2.zip | |
refactor: Parse inputs to double in parameter
Diffstat (limited to 'api/WhatApi/Endpoints/GetPlacesEndpoint.cs')
| -rw-r--r-- | api/WhatApi/Endpoints/GetPlacesEndpoint.cs | 13 |
1 files changed, 4 insertions, 9 deletions
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<ActionResult> 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<ActionResult> HandleAsync(double w, double s, double e, double n, CancellationToken ct = default) { IQueryable<Place> 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}) ) """); } |
