Revert to .NET 9 and separate transport info into ShiftTransport class

Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-08-19 15:10:11 +00:00
parent ee08781543
commit 090476c785
10 changed files with 42 additions and 36 deletions

View file

@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly"> <Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.8" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.8" PrivateAssets="all" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.8" PrivateAssets="all" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -44,16 +44,18 @@ namespace ShiftScheduler.Server.Controllers
[HttpPost("export_ics")] [HttpPost("export_ics")]
public async Task<IActionResult> ExportIcs([FromBody] Dictionary<DateTime, string> schedule) public async Task<IActionResult> ExportIcs([FromBody] Dictionary<DateTime, string> schedule)
{ {
var enrichedShifts = await _enrichmentService.EnrichShiftsWithTransportAsync(_shiftService.GetShifts(), schedule); var shifts = _shiftService.GetShifts();
var ics = _icsService.GenerateIcs(schedule, enrichedShifts); 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"); return File(System.Text.Encoding.UTF8.GetBytes(ics), "text/calendar", "schedule.ics");
} }
[HttpPost("export_pdf")] [HttpPost("export_pdf")]
public async Task<IActionResult> ExportPdf([FromBody] Dictionary<DateTime, string> schedule) public async Task<IActionResult> ExportPdf([FromBody] Dictionary<DateTime, string> schedule)
{ {
var enrichedShifts = await _enrichmentService.EnrichShiftsWithTransportAsync(_shiftService.GetShifts(), schedule); var shifts = _shiftService.GetShifts();
var pdf = _pdfExportService.GenerateMonthlySchedulePdf(schedule, enrichedShifts); var shiftTransports = await _enrichmentService.EnrichShiftsWithTransportAsync(shifts, schedule);
var pdf = _pdfExportService.GenerateMonthlySchedulePdf(schedule, shifts, shiftTransports);
return File(pdf, "application/pdf", "schedule.pdf"); return File(pdf, "application/pdf", "schedule.pdf");
} }
} }

View file

@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.8" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="9.0.8" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -8,7 +8,7 @@ namespace ShiftScheduler.Services
{ {
public class IcsExportService public class IcsExportService
{ {
public string GenerateIcs(Dictionary<DateTime, string> schedule, List<Shift> shifts) public string GenerateIcs(Dictionary<DateTime, string> schedule, List<Shift> shifts, List<ShiftTransport>? shiftTransports = null)
{ {
var calendar = new Calendar(); var calendar = new Calendar();
@ -17,6 +17,7 @@ namespace ShiftScheduler.Services
var date = kvp.Key; var date = kvp.Key;
var shiftName = kvp.Value; var shiftName = kvp.Value;
var shift = shifts.FirstOrDefault(s => s.Name == shiftName); 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))) if (shift == null || (string.IsNullOrEmpty(shift.MorningTime) && string.IsNullOrEmpty(shift.AfternoonTime)))
continue; continue;
@ -27,9 +28,9 @@ namespace ShiftScheduler.Services
var summary = $"{shift.Name} (Morning)"; var summary = $"{shift.Name} (Morning)";
var description = ""; 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}"; description = $"Transport: {transportSummary}";
} }
@ -48,9 +49,9 @@ namespace ShiftScheduler.Services
var summary = $"{shift.Name} (Afternoon)"; var summary = $"{shift.Name} (Afternoon)";
var description = ""; 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}"; description = $"Transport: {transportSummary}";
} }

View file

@ -13,7 +13,7 @@ namespace ShiftScheduler.Services
QuestPDF.Settings.License = LicenseType.Community; QuestPDF.Settings.License = LicenseType.Community;
} }
public byte[] GenerateMonthlySchedulePdf(Dictionary<DateTime, string> schedule, List<Shift> shifts) public byte[] GenerateMonthlySchedulePdf(Dictionary<DateTime, string> schedule, List<Shift> shifts, List<ShiftTransport>? shiftTransports = null)
{ {
var year = schedule.First().Key.Year; var year = schedule.First().Key.Year;
var month = schedule.First().Key.Month; var month = schedule.First().Key.Month;
@ -68,7 +68,8 @@ namespace ShiftScheduler.Services
table.Cell().Text($"{shift.MorningTime} - {shift.AfternoonTime}"); table.Cell().Text($"{shift.MorningTime} - {shift.AfternoonTime}");
// Add transport information // Add transport information
var transportInfo = GetTransportSummary(shift); var transport = shiftTransports?.FirstOrDefault(t => t.ShiftName == shift.Name);
var transportInfo = GetTransportSummary(transport);
table.Cell().Text(transportInfo); table.Cell().Text(transportInfo);
if (!string.IsNullOrWhiteSpace(shift.Icon)) if (!string.IsNullOrWhiteSpace(shift.Icon))
@ -102,19 +103,19 @@ namespace ShiftScheduler.Services
return document.GeneratePdf(); return document.GeneratePdf();
} }
private string GetTransportSummary(Shift shift) private string GetTransportSummary(ShiftTransport? transport)
{ {
var transportLines = new List<string>(); var transportLines = new List<string>();
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); 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); transportLines.Add(afternoonInfo);
} }

View file

@ -11,18 +11,15 @@ namespace ShiftScheduler.Services
_transportService = transportService; _transportService = transportService;
} }
public async Task<List<Shift>> EnrichShiftsWithTransportAsync(List<Shift> shifts, Dictionary<DateTime, string> schedule) public async Task<List<ShiftTransport>> EnrichShiftsWithTransportAsync(List<Shift> shifts, Dictionary<DateTime, string> schedule)
{ {
var enrichedShifts = new List<Shift>(); var shiftTransports = new List<ShiftTransport>();
foreach (var shift in shifts) foreach (var shift in shifts)
{ {
var enrichedShift = new Shift var shiftTransport = new ShiftTransport
{ {
Name = shift.Name, ShiftName = shift.Name
Icon = shift.Icon,
MorningTime = shift.MorningTime,
AfternoonTime = shift.AfternoonTime
}; };
// Find dates where this shift is scheduled // Find dates where this shift is scheduled
@ -39,7 +36,7 @@ namespace ShiftScheduler.Services
var morningStartTime = ParseShiftTime(sampleDate, shift.MorningTime); var morningStartTime = ParseShiftTime(sampleDate, shift.MorningTime);
if (morningStartTime.HasValue) 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); var afternoonStartTime = ParseShiftTime(sampleDate, shift.AfternoonTime);
if (afternoonStartTime.HasValue) 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) private DateTime? ParseShiftTime(DateTime date, string timeRange)

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>

View file

@ -6,7 +6,5 @@ namespace ShiftScheduler.Shared.Models
public string Icon { get; set; } = string.Empty; public string Icon { get; set; } = string.Empty;
public string MorningTime { get; set; } = string.Empty; public string MorningTime { get; set; } = string.Empty;
public string AfternoonTime { get; set; } = string.Empty; public string AfternoonTime { get; set; } = string.Empty;
public TransportConnection? MorningTransport { get; set; }
public TransportConnection? AfternoonTransport { get; set; }
} }
} }

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>

View file

@ -1,5 +1,12 @@
namespace ShiftScheduler.Shared.Models 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 class TransportConfiguration
{ {
public string StartStation { get; set; } = string.Empty; public string StartStation { get; set; } = string.Empty;