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">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.8" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.8" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>

View file

@ -44,16 +44,18 @@ namespace ShiftScheduler.Server.Controllers
[HttpPost("export_ics")]
public async Task<IActionResult> ExportIcs([FromBody] Dictionary<DateTime, string> 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<IActionResult> ExportPdf([FromBody] Dictionary<DateTime, string> 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");
}
}

View file

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

View file

@ -8,7 +8,7 @@ namespace ShiftScheduler.Services
{
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();
@ -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}";
}

View file

@ -13,7 +13,7 @@ namespace ShiftScheduler.Services
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 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<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);
}
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);
}

View file

@ -11,18 +11,15 @@ namespace ShiftScheduler.Services
_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)
{
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)

View file

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

View file

@ -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; }
}
}

View file

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

View file

@ -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;