aboutsummaryrefslogtreecommitdiff
path: root/src/Costasdev.Busurbano.Backend/Controllers/RoutePlannerController.cs
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2025-12-28 15:59:32 +0100
committerAriel Costas Guerrero <ariel@costas.dev>2025-12-28 15:59:50 +0100
commit4fb2fe683b75464917dec4b1a0aaee63830f3b9a (patch)
tree40b48d9717061db2bc3434b5db085eeeaae6cd76 /src/Costasdev.Busurbano.Backend/Controllers/RoutePlannerController.cs
parent1fd17d4d07d25a810816e4e38ddc31ae72b8c91a (diff)
feat: Refactor NavBar and Planner components; update geocoding services
- Removed unused Navigation2 icon from NavBar. - Updated usePlanner hook to manage route history and improve local storage handling. - Enhanced PlannerApi with new fare properties and improved itinerary handling. - Added recent routes feature in StopList with navigation to planner. - Implemented NominatimGeocodingService for autocomplete and reverse geocoding. - Updated UI components for better user experience and accessibility. - Added translations for recent routes in multiple languages. - Improved CSS styles for map controls and overall layout.
Diffstat (limited to 'src/Costasdev.Busurbano.Backend/Controllers/RoutePlannerController.cs')
-rw-r--r--src/Costasdev.Busurbano.Backend/Controllers/RoutePlannerController.cs14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/Costasdev.Busurbano.Backend/Controllers/RoutePlannerController.cs b/src/Costasdev.Busurbano.Backend/Controllers/RoutePlannerController.cs
index 7d47383..a7faf44 100644
--- a/src/Costasdev.Busurbano.Backend/Controllers/RoutePlannerController.cs
+++ b/src/Costasdev.Busurbano.Backend/Controllers/RoutePlannerController.cs
@@ -15,18 +15,21 @@ public partial class RoutePlannerController : ControllerBase
{
private readonly ILogger<RoutePlannerController> _logger;
private readonly OtpService _otpService;
+ private readonly IGeocodingService _geocodingService;
private readonly AppConfiguration _config;
private readonly HttpClient _httpClient;
public RoutePlannerController(
ILogger<RoutePlannerController> logger,
OtpService otpService,
+ IGeocodingService geocodingService,
IOptions<AppConfiguration> config,
HttpClient httpClient
)
{
_logger = logger;
_otpService = otpService;
+ _geocodingService = geocodingService;
_config = config.Value;
_httpClient = httpClient;
}
@@ -39,14 +42,14 @@ public partial class RoutePlannerController : ControllerBase
return BadRequest("Query cannot be empty");
}
- var results = await _otpService.GetAutocompleteAsync(query);
+ var results = await _geocodingService.GetAutocompleteAsync(query);
return Ok(results);
}
[HttpGet("reverse")]
public async Task<ActionResult<PlannerSearchResult>> Reverse([FromQuery] double lat, [FromQuery] double lon)
{
- var result = await _otpService.GetReverseGeocodeAsync(lat, lon);
+ var result = await _geocodingService.GetReverseGeocodeAsync(lat, lon);
if (result == null)
{
return NotFound();
@@ -60,13 +63,13 @@ public partial class RoutePlannerController : ControllerBase
[FromQuery] double fromLon,
[FromQuery] double toLat,
[FromQuery] double toLon,
- [FromQuery] DateTimeOffset time,
+ [FromQuery] DateTimeOffset? time,
[FromQuery] bool arriveBy = false)
{
try
{
var requestContent = PlanConnectionContent.Query(
- new PlanConnectionContent.Args(fromLat, fromLon, toLat, toLon, time, arriveBy)
+ new PlanConnectionContent.Args(fromLat, fromLon, toLat, toLon, time ?? DateTimeOffset.Now, arriveBy)
);
var request = new HttpRequestMessage(HttpMethod.Post, $"{_config.OpenTripPlannerBaseUrl}/gtfs/v1");
@@ -78,7 +81,7 @@ public partial class RoutePlannerController : ControllerBase
var response = await _httpClient.SendAsync(request);
var responseBody = await response.Content.ReadFromJsonAsync<GraphClientResponse<PlanConnectionResponse>>();
- if (responseBody is not { IsSuccess: true } || responseBody.Data?.PlanConnection.Edges.Length == 0)
+ if (responseBody is not { IsSuccess: true })
{
LogErrorFetchingRoutes(response.StatusCode, await response.Content.ReadAsStringAsync());
return StatusCode(500, "An error occurred while planning the route.");
@@ -96,5 +99,4 @@ public partial class RoutePlannerController : ControllerBase
[LoggerMessage(LogLevel.Error, "Error fetching route planning, received {statusCode} {responseBody}")]
partial void LogErrorFetchingRoutes(HttpStatusCode? statusCode, string responseBody);
-
}