aboutsummaryrefslogtreecommitdiff
path: root/src/Enmarcha.Backend/Services/ArrivalsPipeline.cs
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2025-12-29 00:41:52 +0100
committerAriel Costas Guerrero <ariel@costas.dev>2025-12-29 00:41:52 +0100
commita304c24b32c0327436bbd8c2853e60668e161b42 (patch)
tree08f65c05daca134cf4d2e4f779bd15d98fd66370 /src/Enmarcha.Backend/Services/ArrivalsPipeline.cs
parent120a3c6bddd0fb8d9fa05df4763596956554c025 (diff)
Rename a lot of stuff, add Santiago real time
Diffstat (limited to 'src/Enmarcha.Backend/Services/ArrivalsPipeline.cs')
-rw-r--r--src/Enmarcha.Backend/Services/ArrivalsPipeline.cs61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/Enmarcha.Backend/Services/ArrivalsPipeline.cs b/src/Enmarcha.Backend/Services/ArrivalsPipeline.cs
new file mode 100644
index 0000000..57a46e1
--- /dev/null
+++ b/src/Enmarcha.Backend/Services/ArrivalsPipeline.cs
@@ -0,0 +1,61 @@
+using Enmarcha.Backend.Types;
+using Enmarcha.Backend.Types.Arrivals;
+
+namespace Enmarcha.Backend.Services;
+
+public class ArrivalsContext
+{
+ /// <summary>
+ /// The full GTFS ID of the stop (e.g., "vitrasa:1400")
+ /// </summary>
+ public required string StopId { get; set; }
+
+ /// <summary>
+ /// The public code of the stop (e.g., "1400")
+ /// </summary>
+ public required string StopCode { get; set; }
+
+ /// <summary>
+ /// Whether to return a reduced number of arrivals (e.g., 4 instead of 10)
+ /// </summary>
+ public bool IsReduced { get; set; }
+
+ public Position? StopLocation { get; set; }
+
+ public required List<Arrival> Arrivals { get; set; }
+ public required DateTime NowLocal { get; set; }
+}
+
+public interface IArrivalsProcessor
+{
+ /// <summary>
+ /// Processes the arrivals in the context. Processors are executed in the order they are registered.
+ /// </summary>
+ Task ProcessAsync(ArrivalsContext context);
+}
+
+/// <summary>
+/// Orchestrates the enrichment of arrival data through a series of processors.
+/// This follows a pipeline pattern where each step (processor) adds or modifies data
+/// in the shared ArrivalsContext.
+/// </summary>
+public class ArrivalsPipeline
+{
+ private readonly IEnumerable<IArrivalsProcessor> _processors;
+
+ public ArrivalsPipeline(IEnumerable<IArrivalsProcessor> processors)
+ {
+ _processors = processors;
+ }
+
+ /// <summary>
+ /// Executes all registered processors sequentially.
+ /// </summary>
+ public async Task ExecuteAsync(ArrivalsContext context)
+ {
+ foreach (var processor in _processors)
+ {
+ await processor.ProcessAsync(context);
+ }
+ }
+}