From 4b7eaa318f22d7cc768491c421cb7aeac477f95d Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Mon, 22 Dec 2025 18:16:57 +0100 Subject: Implement retrieving next arrivals for a stop (scheduled only) --- .../Types/Arrivals/Arrival.cs | 82 ++++++++++++++++++++++ .../Types/Arrivals/StopArrivalsResponse.cs | 15 ++++ .../Types/Otp/OtpModels.cs | 4 +- .../Types/Planner/PlannerModels.cs | 80 --------------------- .../Types/Planner/PlannerResponse.cs | 80 +++++++++++++++++++++ 5 files changed, 179 insertions(+), 82 deletions(-) create mode 100644 src/Costasdev.Busurbano.Backend/Types/Arrivals/Arrival.cs create mode 100644 src/Costasdev.Busurbano.Backend/Types/Arrivals/StopArrivalsResponse.cs delete mode 100644 src/Costasdev.Busurbano.Backend/Types/Planner/PlannerModels.cs create mode 100644 src/Costasdev.Busurbano.Backend/Types/Planner/PlannerResponse.cs (limited to 'src/Costasdev.Busurbano.Backend/Types') diff --git a/src/Costasdev.Busurbano.Backend/Types/Arrivals/Arrival.cs b/src/Costasdev.Busurbano.Backend/Types/Arrivals/Arrival.cs new file mode 100644 index 0000000..c813ccf --- /dev/null +++ b/src/Costasdev.Busurbano.Backend/Types/Arrivals/Arrival.cs @@ -0,0 +1,82 @@ +using System.Text.Json.Serialization; + +namespace Costasdev.Busurbano.Backend.Types.Arrivals; + +public class Arrival +{ + [JsonPropertyName("route")] + public required RouteInfo Route { get; set; } + + [JsonPropertyName("headsign")] + public required HeadsignInfo Headsign { get; set; } + + [JsonPropertyName("estimate")] + public required ArrivalDetails Estimate { get; set; } + + [JsonPropertyName("delay")] + public DelayBadge? Delay { get; set; } + + [JsonPropertyName("shift")] + public ShiftBadge? Shift { get; set; } +} + +public class RouteInfo +{ + [JsonPropertyName("shortName")] + public required string ShortName { get; set; } + + [JsonPropertyName("colour")] + public required string Colour { get; set; } + + [JsonPropertyName("textColour")] + public required string TextColour { get; set; } +} + +public class HeadsignInfo +{ + [JsonPropertyName("badge")] + public string? Badge { get; set; } + + [JsonPropertyName("destination")] + public required string Destination { get; set; } + + [JsonPropertyName("marquee")] + public string? Marquee { get; set; } +} + +public class ArrivalDetails +{ + [JsonPropertyName("minutes")] + public required int Minutes { get; set; } + + [JsonPropertyName("precission")] + public ArrivalPrecission Precission { get; set; } = ArrivalPrecission.Scheduled; +} + +[JsonConverter(typeof(JsonStringEnumConverter))] +public enum ArrivalPrecission +{ + [JsonStringEnumMemberName("confident")] + Confident = 0, + [JsonStringEnumMemberName("unsure")] + Unsure = 1, + [JsonStringEnumMemberName("scheduled")] + Scheduled = 2, + [JsonStringEnumMemberName("past")] + Past = 3 +} + +public class DelayBadge +{ + [JsonPropertyName("minutes")] + public int Minutes { get; set; } +} + +public class ShiftBadge +{ + [JsonPropertyName("shiftName")] + public string ShiftName { get; set; } + + [JsonPropertyName("shiftTrip")] + public string ShiftTrip { get; set; } +} diff --git a/src/Costasdev.Busurbano.Backend/Types/Arrivals/StopArrivalsResponse.cs b/src/Costasdev.Busurbano.Backend/Types/Arrivals/StopArrivalsResponse.cs new file mode 100644 index 0000000..8c5438c --- /dev/null +++ b/src/Costasdev.Busurbano.Backend/Types/Arrivals/StopArrivalsResponse.cs @@ -0,0 +1,15 @@ +using System.Text.Json.Serialization; + +namespace Costasdev.Busurbano.Backend.Types.Arrivals; + +public class StopArrivalsResponse +{ + [JsonPropertyName("stopCode")] + public required string StopCode { get; set; } + + [JsonPropertyName("stopName")] + public required string StopName { get; set; } + + [JsonPropertyName("arrivals")] + public List Arrivals { get; set; } = []; +} diff --git a/src/Costasdev.Busurbano.Backend/Types/Otp/OtpModels.cs b/src/Costasdev.Busurbano.Backend/Types/Otp/OtpModels.cs index 1c47a4a..b67663d 100644 --- a/src/Costasdev.Busurbano.Backend/Types/Otp/OtpModels.cs +++ b/src/Costasdev.Busurbano.Backend/Types/Otp/OtpModels.cs @@ -98,7 +98,7 @@ public class OtpLeg public OtpGeometry? LegGeometry { get; set; } [JsonPropertyName("steps")] - public List Steps { get; set; } = new(); + public List Steps { get; set; } = []; [JsonPropertyName("headsign")] public string? Headsign { get; set; } @@ -113,7 +113,7 @@ public class OtpLeg public string? RouteTextColor { get; set; } [JsonPropertyName("intermediateStops")] - public List IntermediateStops { get; set; } = new(); + public List IntermediateStops { get; set; } = []; } public class OtpPlace diff --git a/src/Costasdev.Busurbano.Backend/Types/Planner/PlannerModels.cs b/src/Costasdev.Busurbano.Backend/Types/Planner/PlannerModels.cs deleted file mode 100644 index c31d12a..0000000 --- a/src/Costasdev.Busurbano.Backend/Types/Planner/PlannerModels.cs +++ /dev/null @@ -1,80 +0,0 @@ -namespace Costasdev.Busurbano.Backend.Types.Planner; - -public class RoutePlan -{ - public List Itineraries { get; set; } = new(); - public long? TimeOffsetSeconds { get; set; } -} - -public class Itinerary -{ - public double DurationSeconds { get; set; } - public DateTime StartTime { get; set; } - public DateTime EndTime { get; set; } - public double WalkDistanceMeters { get; set; } - public double WalkTimeSeconds { get; set; } - public double TransitTimeSeconds { get; set; } - public double WaitingTimeSeconds { get; set; } - public List Legs { get; set; } = new(); - public double? CashFareEuro { get; set; } - public double? CardFareEuro { get; set; } -} - -public class Leg -{ - public string? Mode { get; set; } // WALK, BUS, etc. - public string? RouteName { get; set; } - public string? RouteShortName { get; set; } - public string? RouteLongName { get; set; } - public string? Headsign { get; set; } - public string? AgencyName { get; set; } - public string? RouteColor { get; set; } - public string? RouteTextColor { get; set; } - public PlannerPlace? From { get; set; } - public PlannerPlace? To { get; set; } - public DateTime StartTime { get; set; } - public DateTime EndTime { get; set; } - public double DistanceMeters { get; set; } - - // GeoJSON LineString geometry - public PlannerGeometry? Geometry { get; set; } - - public List Steps { get; set; } = new(); - - public List IntermediateStops { get; set; } = new(); -} - -public class PlannerPlace -{ - public string? Name { get; set; } - public double Lat { get; set; } - public double Lon { get; set; } - public string? StopId { get; set; } - public string? StopCode { get; set; } -} - -public class PlannerGeometry -{ - public string Type { get; set; } = "LineString"; - public List> Coordinates { get; set; } = new(); // [[lon, lat], ...] -} - -public class Step -{ - public double DistanceMeters { get; set; } - public string? RelativeDirection { get; set; } - public string? AbsoluteDirection { get; set; } - public string? StreetName { get; set; } - public double Lat { get; set; } - public double Lon { get; set; } -} - -// For Autocomplete/Reverse -public class PlannerSearchResult -{ - public string? Name { get; set; } - public string? Label { get; set; } - public double Lat { get; set; } - public double Lon { get; set; } - public string? Layer { get; set; } -} diff --git a/src/Costasdev.Busurbano.Backend/Types/Planner/PlannerResponse.cs b/src/Costasdev.Busurbano.Backend/Types/Planner/PlannerResponse.cs new file mode 100644 index 0000000..c31d12a --- /dev/null +++ b/src/Costasdev.Busurbano.Backend/Types/Planner/PlannerResponse.cs @@ -0,0 +1,80 @@ +namespace Costasdev.Busurbano.Backend.Types.Planner; + +public class RoutePlan +{ + public List Itineraries { get; set; } = new(); + public long? TimeOffsetSeconds { get; set; } +} + +public class Itinerary +{ + public double DurationSeconds { get; set; } + public DateTime StartTime { get; set; } + public DateTime EndTime { get; set; } + public double WalkDistanceMeters { get; set; } + public double WalkTimeSeconds { get; set; } + public double TransitTimeSeconds { get; set; } + public double WaitingTimeSeconds { get; set; } + public List Legs { get; set; } = new(); + public double? CashFareEuro { get; set; } + public double? CardFareEuro { get; set; } +} + +public class Leg +{ + public string? Mode { get; set; } // WALK, BUS, etc. + public string? RouteName { get; set; } + public string? RouteShortName { get; set; } + public string? RouteLongName { get; set; } + public string? Headsign { get; set; } + public string? AgencyName { get; set; } + public string? RouteColor { get; set; } + public string? RouteTextColor { get; set; } + public PlannerPlace? From { get; set; } + public PlannerPlace? To { get; set; } + public DateTime StartTime { get; set; } + public DateTime EndTime { get; set; } + public double DistanceMeters { get; set; } + + // GeoJSON LineString geometry + public PlannerGeometry? Geometry { get; set; } + + public List Steps { get; set; } = new(); + + public List IntermediateStops { get; set; } = new(); +} + +public class PlannerPlace +{ + public string? Name { get; set; } + public double Lat { get; set; } + public double Lon { get; set; } + public string? StopId { get; set; } + public string? StopCode { get; set; } +} + +public class PlannerGeometry +{ + public string Type { get; set; } = "LineString"; + public List> Coordinates { get; set; } = new(); // [[lon, lat], ...] +} + +public class Step +{ + public double DistanceMeters { get; set; } + public string? RelativeDirection { get; set; } + public string? AbsoluteDirection { get; set; } + public string? StreetName { get; set; } + public double Lat { get; set; } + public double Lon { get; set; } +} + +// For Autocomplete/Reverse +public class PlannerSearchResult +{ + public string? Name { get; set; } + public string? Label { get; set; } + public double Lat { get; set; } + public double Lon { get; set; } + public string? Layer { get; set; } +} -- cgit v1.3