aboutsummaryrefslogtreecommitdiff
path: root/src/Enmarcha.Backend/Services
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2026-01-25 21:35:36 +0100
committerAriel Costas Guerrero <ariel@costas.dev>2026-01-25 21:35:36 +0100
commit6192730d1b7b0d08095d7da88caba73fd07fe99e (patch)
tree4a62610d8b8ee42c79380f2e4d3eb1480caccbf5 /src/Enmarcha.Backend/Services
parentf9b7af64550be1320acc84d60184e8c8ce873b94 (diff)
Bring back basic stop search
Diffstat (limited to 'src/Enmarcha.Backend/Services')
-rw-r--r--src/Enmarcha.Backend/Services/OtpService.cs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/Enmarcha.Backend/Services/OtpService.cs b/src/Enmarcha.Backend/Services/OtpService.cs
index e4b4846..1484583 100644
--- a/src/Enmarcha.Backend/Services/OtpService.cs
+++ b/src/Enmarcha.Backend/Services/OtpService.cs
@@ -5,6 +5,7 @@ using Enmarcha.Backend.Helpers;
using Enmarcha.Backend.Types.Otp;
using Enmarcha.Backend.Types.Planner;
using Enmarcha.Backend.Types.Transit;
+using Enmarcha.Sources.OpenTripPlannerGql;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
@@ -89,6 +90,42 @@ public class OtpService
};
}
+ public async Task<List<StopTileResponse.Stop>> GetStopsByBboxAsync(double minLon, double minLat, double maxLon, double maxLat)
+ {
+ const string cacheKey = "otp_all_stops_detailed";
+ if (_cache.TryGetValue(cacheKey, out List<StopTileResponse.Stop>? cachedStops) && cachedStops != null)
+ {
+ return cachedStops;
+ }
+
+ try
+ {
+ var bbox = new StopTileRequestContent.Bbox(minLon, minLat, maxLon, maxLat);
+ var query = StopTileRequestContent.Query(bbox);
+
+ var request = new HttpRequestMessage(HttpMethod.Post, $"{_config.OpenTripPlannerBaseUrl}/gtfs/v1");
+ request.Content = JsonContent.Create(new GraphClientRequest { Query = query });
+
+ var response = await _httpClient.SendAsync(request);
+ var responseBody = await response.Content.ReadFromJsonAsync<GraphClientResponse<StopTileResponse>>();
+
+ if (responseBody is not { IsSuccess: true } || responseBody.Data?.StopsByBbox == null)
+ {
+ _logger.LogError("Error fetching stops from OTP for caching");
+ return new List<StopTileResponse.Stop>();
+ }
+
+ var stops = responseBody.Data.StopsByBbox;
+ _cache.Set(cacheKey, stops, TimeSpan.FromHours(18));
+ return stops;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Exception fetching stops from OTP for caching");
+ return new List<StopTileResponse.Stop>();
+ }
+ }
+
private Leg MapLeg(OtpLeg otpLeg)
{
return new Leg