diff --git a/Client/ShiftScheduler.Client.csproj b/Client/ShiftScheduler.Client.csproj index 75d9930..822d92e 100644 --- a/Client/ShiftScheduler.Client.csproj +++ b/Client/ShiftScheduler.Client.csproj @@ -1,14 +1,14 @@ - net8.0 + net9.0 enable enable - - + + diff --git a/Server/Controllers/ShiftController.cs b/Server/Controllers/ShiftController.cs index 8108216..51898e2 100644 --- a/Server/Controllers/ShiftController.cs +++ b/Server/Controllers/ShiftController.cs @@ -44,16 +44,18 @@ namespace ShiftScheduler.Server.Controllers [HttpPost("export_ics")] public async Task ExportIcs([FromBody] Dictionary schedule) { - var enrichedShifts = await _enrichmentService.EnrichShiftsWithTransportAsync(_shiftService.GetShifts(), schedule); - var ics = _icsService.GenerateIcs(schedule, enrichedShifts); + var shifts = _shiftService.GetShifts(); + var shiftTransports = await _enrichmentService.EnrichShiftsWithTransportAsync(shifts, schedule); + var ics = _icsService.GenerateIcs(schedule, shifts, shiftTransports); return File(System.Text.Encoding.UTF8.GetBytes(ics), "text/calendar", "schedule.ics"); } [HttpPost("export_pdf")] public async Task ExportPdf([FromBody] Dictionary schedule) { - var enrichedShifts = await _enrichmentService.EnrichShiftsWithTransportAsync(_shiftService.GetShifts(), schedule); - var pdf = _pdfExportService.GenerateMonthlySchedulePdf(schedule, enrichedShifts); + var shifts = _shiftService.GetShifts(); + var shiftTransports = await _enrichmentService.EnrichShiftsWithTransportAsync(shifts, schedule); + var pdf = _pdfExportService.GenerateMonthlySchedulePdf(schedule, shifts, shiftTransports); return File(pdf, "application/pdf", "schedule.pdf"); } } diff --git a/Server/ShiftScheduler.Server.csproj b/Server/ShiftScheduler.Server.csproj index e41c03e..d35c1ba 100644 --- a/Server/ShiftScheduler.Server.csproj +++ b/Server/ShiftScheduler.Server.csproj @@ -1,13 +1,13 @@ - net8.0 + net9.0 enable enable - + diff --git a/Services/IcsExportService.cs b/Services/IcsExportService.cs index 56de9c8..f6baafd 100644 --- a/Services/IcsExportService.cs +++ b/Services/IcsExportService.cs @@ -8,7 +8,7 @@ namespace ShiftScheduler.Services { public class IcsExportService { - public string GenerateIcs(Dictionary schedule, List shifts) + public string GenerateIcs(Dictionary schedule, List shifts, List? shiftTransports = null) { var calendar = new Calendar(); @@ -17,6 +17,7 @@ namespace ShiftScheduler.Services var date = kvp.Key; var shiftName = kvp.Value; var shift = shifts.FirstOrDefault(s => s.Name == shiftName); + var transport = shiftTransports?.FirstOrDefault(t => t.ShiftName == shiftName); if (shift == null || (string.IsNullOrEmpty(shift.MorningTime) && string.IsNullOrEmpty(shift.AfternoonTime))) continue; @@ -27,9 +28,9 @@ namespace ShiftScheduler.Services var summary = $"{shift.Name} (Morning)"; var description = ""; - if (shift.MorningTransport != null && !string.IsNullOrEmpty(shift.MorningTransport.DepartureTime)) + if (transport?.MorningTransport != null && !string.IsNullOrEmpty(transport.MorningTransport.DepartureTime)) { - var transportSummary = FormatTransportInfo(shift.MorningTransport); + var transportSummary = FormatTransportInfo(transport.MorningTransport); description = $"Transport: {transportSummary}"; } @@ -48,9 +49,9 @@ namespace ShiftScheduler.Services var summary = $"{shift.Name} (Afternoon)"; var description = ""; - if (shift.AfternoonTransport != null && !string.IsNullOrEmpty(shift.AfternoonTransport.DepartureTime)) + if (transport?.AfternoonTransport != null && !string.IsNullOrEmpty(transport.AfternoonTransport.DepartureTime)) { - var transportSummary = FormatTransportInfo(shift.AfternoonTransport); + var transportSummary = FormatTransportInfo(transport.AfternoonTransport); description = $"Transport: {transportSummary}"; } diff --git a/Services/PdfExportService.cs b/Services/PdfExportService.cs index ca96085..20ce463 100644 --- a/Services/PdfExportService.cs +++ b/Services/PdfExportService.cs @@ -13,7 +13,7 @@ namespace ShiftScheduler.Services QuestPDF.Settings.License = LicenseType.Community; } - public byte[] GenerateMonthlySchedulePdf(Dictionary schedule, List shifts) + public byte[] GenerateMonthlySchedulePdf(Dictionary schedule, List shifts, List? shiftTransports = null) { var year = schedule.First().Key.Year; var month = schedule.First().Key.Month; @@ -68,7 +68,8 @@ namespace ShiftScheduler.Services table.Cell().Text($"{shift.MorningTime} - {shift.AfternoonTime}"); // Add transport information - var transportInfo = GetTransportSummary(shift); + var transport = shiftTransports?.FirstOrDefault(t => t.ShiftName == shift.Name); + var transportInfo = GetTransportSummary(transport); table.Cell().Text(transportInfo); if (!string.IsNullOrWhiteSpace(shift.Icon)) @@ -102,19 +103,19 @@ namespace ShiftScheduler.Services return document.GeneratePdf(); } - private string GetTransportSummary(Shift shift) + private string GetTransportSummary(ShiftTransport? transport) { var transportLines = new List(); - if (shift.MorningTransport != null && !string.IsNullOrEmpty(shift.MorningTransport.DepartureTime)) + if (transport?.MorningTransport != null && !string.IsNullOrEmpty(transport.MorningTransport.DepartureTime)) { - var morningInfo = FormatTransportConnection(shift.MorningTransport, "Morning"); + var morningInfo = FormatTransportConnection(transport.MorningTransport, "Morning"); transportLines.Add(morningInfo); } - if (shift.AfternoonTransport != null && !string.IsNullOrEmpty(shift.AfternoonTransport.DepartureTime)) + if (transport?.AfternoonTransport != null && !string.IsNullOrEmpty(transport.AfternoonTransport.DepartureTime)) { - var afternoonInfo = FormatTransportConnection(shift.AfternoonTransport, "Afternoon"); + var afternoonInfo = FormatTransportConnection(transport.AfternoonTransport, "Afternoon"); transportLines.Add(afternoonInfo); } diff --git a/Services/ShiftEnrichmentService.cs b/Services/ShiftEnrichmentService.cs index 2e7005b..26ecb4e 100644 --- a/Services/ShiftEnrichmentService.cs +++ b/Services/ShiftEnrichmentService.cs @@ -11,18 +11,15 @@ namespace ShiftScheduler.Services _transportService = transportService; } - public async Task> EnrichShiftsWithTransportAsync(List shifts, Dictionary schedule) + public async Task> EnrichShiftsWithTransportAsync(List shifts, Dictionary schedule) { - var enrichedShifts = new List(); + var shiftTransports = new List(); foreach (var shift in shifts) { - var enrichedShift = new Shift + var shiftTransport = new ShiftTransport { - Name = shift.Name, - Icon = shift.Icon, - MorningTime = shift.MorningTime, - AfternoonTime = shift.AfternoonTime + ShiftName = shift.Name }; // Find dates where this shift is scheduled @@ -39,7 +36,7 @@ namespace ShiftScheduler.Services var morningStartTime = ParseShiftTime(sampleDate, shift.MorningTime); if (morningStartTime.HasValue) { - enrichedShift.MorningTransport = await _transportService.GetConnectionAsync(morningStartTime.Value); + shiftTransport.MorningTransport = await _transportService.GetConnectionAsync(morningStartTime.Value); } } @@ -49,15 +46,15 @@ namespace ShiftScheduler.Services var afternoonStartTime = ParseShiftTime(sampleDate, shift.AfternoonTime); if (afternoonStartTime.HasValue) { - enrichedShift.AfternoonTransport = await _transportService.GetConnectionAsync(afternoonStartTime.Value); + shiftTransport.AfternoonTransport = await _transportService.GetConnectionAsync(afternoonStartTime.Value); } } } - enrichedShifts.Add(enrichedShift); + shiftTransports.Add(shiftTransport); } - return enrichedShifts; + return shiftTransports; } private DateTime? ParseShiftTime(DateTime date, string timeRange) diff --git a/Services/ShiftScheduler.Services.csproj b/Services/ShiftScheduler.Services.csproj index 14f5f17..ba281ba 100644 --- a/Services/ShiftScheduler.Services.csproj +++ b/Services/ShiftScheduler.Services.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable diff --git a/Shared/Shift.cs b/Shared/Shift.cs index 1fcdd42..6312bc5 100644 --- a/Shared/Shift.cs +++ b/Shared/Shift.cs @@ -6,7 +6,5 @@ namespace ShiftScheduler.Shared.Models public string Icon { get; set; } = string.Empty; public string MorningTime { get; set; } = string.Empty; public string AfternoonTime { get; set; } = string.Empty; - public TransportConnection? MorningTransport { get; set; } - public TransportConnection? AfternoonTransport { get; set; } } } diff --git a/Shared/ShiftScheduler.Shared.csproj b/Shared/ShiftScheduler.Shared.csproj index 9a938be..46f7f7d 100644 --- a/Shared/ShiftScheduler.Shared.csproj +++ b/Shared/ShiftScheduler.Shared.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable diff --git a/Shared/TransportModels.cs b/Shared/TransportModels.cs index 43e94ae..1b133a4 100644 --- a/Shared/TransportModels.cs +++ b/Shared/TransportModels.cs @@ -1,5 +1,12 @@ namespace ShiftScheduler.Shared.Models { + public class ShiftTransport + { + public string ShiftName { get; set; } = string.Empty; + public TransportConnection? MorningTransport { get; set; } + public TransportConnection? AfternoonTransport { get; set; } + } + public class TransportConfiguration { public string StartStation { get; set; } = string.Empty;