Add logging for transport connection logic

This commit is contained in:
Claudio Schaad 2025-08-30 09:29:51 +02:00
parent f09f57c3dd
commit 5a5902fefa
2 changed files with 18 additions and 2 deletions

View file

@ -1,9 +1,10 @@
using System.Text.Json; using System.Text.Json;
using Microsoft.Extensions.Logging;
using ShiftScheduler.Shared; using ShiftScheduler.Shared;
namespace ShiftScheduler.Services namespace ShiftScheduler.Services
{ {
public class TransportApiService(HttpClient httpClient, IConfigurationService configurationService) : ITransportApiService public class TransportApiService(HttpClient httpClient, IConfigurationService configurationService, ILogger<TransportApiService> logger) : ITransportApiService
{ {
public async Task<TransportConnection?> GetConnectionAsync(DateTime shiftStartTime) public async Task<TransportConnection?> GetConnectionAsync(DateTime shiftStartTime)
{ {
@ -24,12 +25,22 @@ namespace ShiftScheduler.Services
if (apiResponse?.Connections.Count > 0) if (apiResponse?.Connections.Count > 0)
{ {
var allConnections = apiResponse.Connections.Select(MapToTransportConnection).ToList(); var allConnections = apiResponse.Connections.Select(MapToTransportConnection).ToList();
return TransportConnectionCalculator.FindBestConnection(
foreach (var connection in allConnections)
{
logger.LogInformation($"Found connection {connection}");
}
var bestConnection = TransportConnectionCalculator.FindBestConnection(
allConnections, allConnections,
shiftStartTime, shiftStartTime,
config.SafetyBufferMinutes, config.SafetyBufferMinutes,
config.MaxEarlyArrivalMinutes, config.MaxEarlyArrivalMinutes,
config.MaxLateArrivalMinutes); config.MaxLateArrivalMinutes);
logger.LogInformation($"Found best {bestConnection}");
return bestConnection;
} }
return null; return null;

View file

@ -19,6 +19,11 @@ namespace ShiftScheduler.Shared
public string Duration { get; set; } = string.Empty; public string Duration { get; set; } = string.Empty;
public string? Platform { get; set; } = string.Empty; public string? Platform { get; set; } = string.Empty;
public List<TransportSection> Sections { get; set; } = new(); public List<TransportSection> Sections { get; set; } = new();
public override string ToString()
{
return $"{Platform}: {DepartureTime} - {ArrivalTime} ({Duration})";
}
} }
public class TransportSection public class TransportSection