summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorivar <i@oiee.no>2025-10-20 00:32:22 +0200
committerivar <i@oiee.no>2025-10-20 00:32:22 +0200
commit440590ee512f9d4214334d870ca21dc2f39235a2 (patch)
tree1720a7f54e15fe3cf207ca48de57cf265567635b /api
parenta1f0518d0cd123a791adde64f4f11bd8e44276c7 (diff)
downloadwhat-440590ee512f9d4214334d870ca21dc2f39235a2.tar.xz
what-440590ee512f9d4214334d870ca21dc2f39235a2.zip
refactor: Parse inputs to double in parameter
Diffstat (limited to 'api')
-rw-r--r--api/.idea/.idea.WhatApi/.idea/.name1
-rw-r--r--api/.idea/.idea.WhatApi/.idea/vcs.xml6
-rw-r--r--api/WhatApi/Endpoints/GetPlacesEndpoint.cs13
3 files changed, 11 insertions, 9 deletions
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="VcsDirectoryMappings">
+ <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
+ </component>
+</project> \ 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<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})
)
""");
}