aboutsummaryrefslogtreecommitdiff
path: root/src/Costasdev.Busurbano.Backend/Controllers/VigoController.Legacy.cs
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2025-12-19 13:06:27 +0100
committerAriel Costas Guerrero <ariel@costas.dev>2025-12-19 13:06:27 +0100
commit2a9aca302485bc08f5b2dd2a54987de6f80fc338 (patch)
tree38171abad21b2952eca6ff9e8534545b4c28ed12 /src/Costasdev.Busurbano.Backend/Controllers/VigoController.Legacy.cs
parent37cdb0c418a7f2b47e40ae9db7ad86e1fddc86fe (diff)
Implement loading stops as tiles from OTP
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, 0 insertions, 78 deletions
diff --git a/src/Costasdev.Busurbano.Backend/Controllers/VigoController.Legacy.cs b/src/Costasdev.Busurbano.Backend/Controllers/VigoController.Legacy.cs
deleted file mode 100644
index d006e38..0000000
--- a/src/Costasdev.Busurbano.Backend/Controllers/VigoController.Legacy.cs
+++ /dev/null
@@ -1,78 +0,0 @@
-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.VitrasaScheduleBasePath, 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");
- }
- }
-
-}