aboutsummaryrefslogtreecommitdiff
path: root/src/Costasdev.Busurbano.Backend/GraphClient/App
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2025-12-22 22:06:06 +0100
committerAriel Costas Guerrero <ariel@costas.dev>2025-12-22 22:06:06 +0100
commitbed48c3d7e49b1736d50ce42d92bb6c18cf02504 (patch)
tree475571ad6fa8c7aa1f8e81520689bf1eb425164c /src/Costasdev.Busurbano.Backend/GraphClient/App
parent68f49dec91d68579803d6d579b1f1ecb4fc1dd1f (diff)
Refactor arrivals handling and improve type definitions; reorganise components
Diffstat (limited to 'src/Costasdev.Busurbano.Backend/GraphClient/App')
-rw-r--r--src/Costasdev.Busurbano.Backend/GraphClient/App/ArrivalsAtStop.cs20
-rw-r--r--src/Costasdev.Busurbano.Backend/GraphClient/App/StopTile.cs20
2 files changed, 25 insertions, 15 deletions
diff --git a/src/Costasdev.Busurbano.Backend/GraphClient/App/ArrivalsAtStop.cs b/src/Costasdev.Busurbano.Backend/GraphClient/App/ArrivalsAtStop.cs
index 53c1165..2c34784 100644
--- a/src/Costasdev.Busurbano.Backend/GraphClient/App/ArrivalsAtStop.cs
+++ b/src/Costasdev.Busurbano.Backend/GraphClient/App/ArrivalsAtStop.cs
@@ -5,16 +5,26 @@ namespace Costasdev.Busurbano.Backend.GraphClient.App;
public class ArrivalsAtStopContent : IGraphRequest<ArrivalsAtStopContent.Args>
{
- public record Args(string Id, int DepartureCount);
+ public const int PastArrivalMinutesIncluded = -15;
+
+ public record Args(string Id, int DepartureCount, bool PastArrivals);
public static string Query(Args args)
{
+ var startTime = DateTimeOffset.Now;
+ if (args.PastArrivals)
+ {
+ startTime = DateTimeOffset.Now.AddMinutes(PastArrivalMinutesIncluded);
+ }
+
+ var startTimeUnix = startTime.ToUnixTimeSeconds();
+
return string.Create(CultureInfo.InvariantCulture, $@"
query Query {{
stop(id:""{args.Id}"") {{
code
name
- arrivals: stoptimesWithoutPatterns(numberOfDepartures:{args.DepartureCount}) {{
+ arrivals: stoptimesWithoutPatterns(numberOfDepartures:{args.DepartureCount}, startTime: {startTimeUnix}) {{
headsign
scheduledDeparture
pickupType
@@ -40,7 +50,7 @@ public class ArrivalsAtStopContent : IGraphRequest<ArrivalsAtStopContent.Args>
public class ArrivalsAtStopResponse : AbstractGraphResponse
{
- [JsonPropertyName("stop")] public StopItem Stop { get; set; }
+ [JsonPropertyName("stop")] public required StopItem Stop { get; set; }
public class StopItem
{
@@ -87,9 +97,9 @@ public class ArrivalsAtStopResponse : AbstractGraphResponse
public class RouteDetails
{
- [JsonPropertyName("color")] public required string Color { get; set; }
+ [JsonPropertyName("color")] public string? Color { get; set; }
- [JsonPropertyName("textColor")] public required string TextColor { get; set; }
+ [JsonPropertyName("textColor")] public string? TextColor { get; set; }
}
public class PickupType
diff --git a/src/Costasdev.Busurbano.Backend/GraphClient/App/StopTile.cs b/src/Costasdev.Busurbano.Backend/GraphClient/App/StopTile.cs
index 8a271f2..802de9a 100644
--- a/src/Costasdev.Busurbano.Backend/GraphClient/App/StopTile.cs
+++ b/src/Costasdev.Busurbano.Backend/GraphClient/App/StopTile.cs
@@ -42,35 +42,35 @@ public class StopTileResponse : AbstractGraphResponse
public record Stop
{
[JsonPropertyName("gtfsId")]
- public required string GtfsId { get; init; }
+ public required string GtfsId { get; set; }
[JsonPropertyName("code")]
- public string? Code { get; init; }
+ public string? Code { get; set; }
[JsonPropertyName("name")]
- public required string Name { get; init; }
+ public required string Name { get; set; }
[JsonPropertyName("lat")]
- public required double Lat { get; init; }
+ public required double Lat { get; set; }
[JsonPropertyName("lon")]
- public required double Lon { get; init; }
+ public required double Lon { get; set; }
[JsonPropertyName("routes")]
- public List<Route>? Routes { get; init; }
+ public List<Route>? Routes { get; set; }
}
public record Route
{
[JsonPropertyName("gtfsId")]
- public required string GtfsId { get; init; }
+ public required string GtfsId { get; set; }
[JsonPropertyName("shortName")]
- public required string ShortName { get; init; }
+ public required string ShortName { get; set; }
[JsonPropertyName("color")]
- public string? Color { get; init; }
+ public string? Color { get; set; }
[JsonPropertyName("textColor")]
- public string? TextColor { get; init; }
+ public string? TextColor { get; set; }
}
}