From 87417c313b455ba0dee19708528cc8d0b830a276 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Tue, 23 Dec 2025 12:59:52 +0100 Subject: Reimplement real time for Vitrasa --- .../Services/ArrivalsPipeline.cs | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/Costasdev.Busurbano.Backend/Services/ArrivalsPipeline.cs (limited to 'src/Costasdev.Busurbano.Backend/Services/ArrivalsPipeline.cs') diff --git a/src/Costasdev.Busurbano.Backend/Services/ArrivalsPipeline.cs b/src/Costasdev.Busurbano.Backend/Services/ArrivalsPipeline.cs new file mode 100644 index 0000000..8699a1e --- /dev/null +++ b/src/Costasdev.Busurbano.Backend/Services/ArrivalsPipeline.cs @@ -0,0 +1,58 @@ +using Costasdev.Busurbano.Backend.Types.Arrivals; + +namespace Costasdev.Busurbano.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 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