From a304c24b32c0327436bbd8c2853e60668e161b42 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Mon, 29 Dec 2025 00:41:52 +0100 Subject: Rename a lot of stuff, add Santiago real time --- src/Enmarcha.Backend/Services/ArrivalsPipeline.cs | 61 +++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/Enmarcha.Backend/Services/ArrivalsPipeline.cs (limited to 'src/Enmarcha.Backend/Services/ArrivalsPipeline.cs') 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 +{ + /// + /// The full GTFS ID of the stop (e.g., "vitrasa:1400") + /// + public required string StopId { get; set; } + + /// + /// The public code of the stop (e.g., "1400") + /// + public required string StopCode { get; set; } + + /// + /// Whether to return a reduced number of arrivals (e.g., 4 instead of 10) + /// + public bool IsReduced { get; set; } + + public Position? StopLocation { get; set; } + + public required List Arrivals { get; set; } + public required DateTime NowLocal { get; set; } +} + +public interface IArrivalsProcessor +{ + /// + /// Processes the arrivals in the context. Processors are executed in the order they are registered. + /// + Task ProcessAsync(ArrivalsContext context); +} + +/// +/// 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. +/// +public class ArrivalsPipeline +{ + private readonly IEnumerable _processors; + + public ArrivalsPipeline(IEnumerable processors) + { + _processors = processors; + } + + /// + /// Executes all registered processors sequentially. + /// + public async Task ExecuteAsync(ArrivalsContext context) + { + foreach (var processor in _processors) + { + await processor.ProcessAsync(context); + } + } +} -- cgit v1.3