aboutsummaryrefslogtreecommitdiff
path: root/src/Costasdev.Busurbano.Backend/Controllers/VigoController.Legacy.cs
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2025-11-30 19:17:02 +0100
committerAriel Costas Guerrero <ariel@costas.dev>2025-11-30 19:17:02 +0100
commitcee521142a4e0673b155d97c3e4825b7fec1987f (patch)
treee8030687f62a63c34ad69cb81eefe8470c55cfee /src/Costasdev.Busurbano.Backend/Controllers/VigoController.Legacy.cs
parente7283ba10d45b42e1274cd13c3d6aabec57c85b4 (diff)
Refactor street name processing and remove unused stop downloader script
- Updated `street_name.py` to simplify street name handling by removing the `re_remove_street_type` regex and exception streets list, replacing them with a dictionary for name replacements. - Deleted the `download-stops.py` script from the Santiago stop downloader, which was no longer needed. - Removed the empty `.gitkeep` file from the overrides directory. - Added a new `VigoController` class to handle stop estimates and timetables, including error handling for missing data. - Introduced `LineFormatterService` to format circulation routes based on specific line conditions.
Diffstat (limited to 'src/Costasdev.Busurbano.Backend/Controllers/VigoController.Legacy.cs')
-rw-r--r--src/Costasdev.Busurbano.Backend/Controllers/VigoController.Legacy.cs78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/Costasdev.Busurbano.Backend/Controllers/VigoController.Legacy.cs b/src/Costasdev.Busurbano.Backend/Controllers/VigoController.Legacy.cs
new file mode 100644
index 0000000..3bb9930
--- /dev/null
+++ b/src/Costasdev.Busurbano.Backend/Controllers/VigoController.Legacy.cs
@@ -0,0 +1,78 @@
+using System.Globalization;
+using System.Text.Json;
+using Costasdev.Busurbano.Backend.Types;
+using Microsoft.AspNetCore.Mvc;
+using SysFile = System.IO.File;
+
+namespace Costasdev.Busurbano.Backend.Controllers;
+
+public partial class VigoController : ControllerBase
+{
+ [HttpGet("GetStopEstimates")]
+ public async Task<IActionResult> Run(
+ [FromQuery] int id
+ )
+ {
+ try
+ {
+ var response = await _api.GetStopEstimates(id);
+ // Return only the estimates array, not the stop metadata
+ return new OkObjectResult(response.Estimates);
+ }
+ catch (InvalidOperationException)
+ {
+ return BadRequest("Stop not found");
+ }
+ }
+
+ [HttpGet("GetStopTimetable")]
+ public async Task<IActionResult> GetStopTimetable(
+ [FromQuery] int stopId,
+ [FromQuery] string? date = null
+)
+ {
+ // Use Europe/Madrid timezone to determine the correct date
+ var tz = TimeZoneInfo.FindSystemTimeZoneById("Europe/Madrid");
+ var nowLocal = TimeZoneInfo.ConvertTime(DateTime.UtcNow, tz);
+
+ // If no date provided or date is "today", use Madrid timezone's current date
+ string effectiveDate;
+ if (string.IsNullOrEmpty(date) || date == "today")
+ {
+ effectiveDate = nowLocal.Date.ToString("yyyy-MM-dd");
+ }
+ else
+ {
+ // Validate provided date format
+ if (!DateTime.TryParseExact(date, "yyyy-MM-dd", null, DateTimeStyles.None, out _))
+ {
+ return BadRequest("Invalid date format. Please use yyyy-MM-dd format.");
+ }
+ effectiveDate = date;
+ }
+
+ try
+ {
+ var file = Path.Combine(_configuration.ScheduleBasePath, effectiveDate, stopId + ".json");
+ if (!SysFile.Exists(file))
+ {
+ throw new FileNotFoundException();
+ }
+
+ var contents = await SysFile.ReadAllTextAsync(file);
+
+ return new OkObjectResult(JsonSerializer.Deserialize<List<ScheduledStop>>(contents)!);
+ }
+ catch (FileNotFoundException ex)
+ {
+ _logger.LogError(ex, "Stop data not found for stop {StopId} on date {Date}", stopId, effectiveDate);
+ return StatusCode(404, $"Stop data not found for stop {stopId} on date {effectiveDate}");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error loading stop data");
+ return StatusCode(500, "Error loading timetable");
+ }
+ }
+
+}