blob: 8699a1e452f108dd7dea0ebbd66ff2bcc6126ace (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
using Costasdev.Busurbano.Backend.Types.Arrivals;
namespace Costasdev.Busurbano.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 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);
}
}
}
|