blob: 41992510db5c379247060ae2a97cd611ad75b614 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
using Costasdev.VigoTransitApi;
using Enmarcha.Backend.Configuration;
using Enmarcha.Backend.Services;
using Enmarcha.Backend.Services.Providers;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
namespace Enmarcha.Backend.Controllers;
[ApiController]
[Route("api/vigo")]
public partial class VigoController : ControllerBase
{
private readonly ILogger<VigoController> _logger;
private readonly VigoTransitApiClient _api;
private readonly AppConfiguration _configuration;
private readonly ShapeTraversalService _shapeService;
private readonly VitrasaTransitProvider _vitrasaProvider;
private readonly RenfeTransitProvider _renfeProvider;
public VigoController(
HttpClient http,
IOptions<AppConfiguration> options,
ILogger<VigoController> logger,
ShapeTraversalService shapeService,
VitrasaTransitProvider vitrasaProvider,
RenfeTransitProvider renfeProvider)
{
_logger = logger;
_api = new VigoTransitApiClient(http);
_configuration = options.Value;
_shapeService = shapeService;
_vitrasaProvider = vitrasaProvider;
_renfeProvider = renfeProvider;
}
[HttpGet("GetConsolidatedCirculations")]
public async Task<IActionResult> GetConsolidatedCirculations(
[FromQuery] string stopId
)
{
// Use Europe/Madrid timezone consistently to avoid UTC/local skew
var tz = TimeZoneInfo.FindSystemTimeZoneById("Europe/Madrid");
var nowLocal = TimeZoneInfo.ConvertTime(DateTime.UtcNow, tz);
ITransitProvider provider;
string effectiveStopId;
if (stopId.StartsWith("renfe:"))
{
provider = _renfeProvider;
effectiveStopId = stopId.Substring("renfe:".Length);
}
else if (stopId.StartsWith("vitrasa:"))
{
provider = _vitrasaProvider;
effectiveStopId = stopId.Substring("vitrasa:".Length);
}
else
{
// Legacy/Default
provider = _vitrasaProvider;
effectiveStopId = stopId;
}
var result = await provider.GetCirculationsAsync(effectiveStopId, nowLocal);
return Ok(result);
}
}
|