From ead947bf57a70bd92f928580681633f1c7394a1a Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Tue, 6 Jan 2026 10:33:36 -0500 Subject: [PATCH] feat(client): migrate WorkOrderFilterPanel to API clients --- .../FilterPanels/WorkOrderFilterPanel.razor | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/NEW/src/JdeScoping.Client/Components/FilterPanels/WorkOrderFilterPanel.razor b/NEW/src/JdeScoping.Client/Components/FilterPanels/WorkOrderFilterPanel.razor index 0f3abd0..2199dbc 100644 --- a/NEW/src/JdeScoping.Client/Components/FilterPanels/WorkOrderFilterPanel.razor +++ b/NEW/src/JdeScoping.Client/Components/FilterPanels/WorkOrderFilterPanel.razor @@ -1,5 +1,6 @@ @* Work order filter panel with upload/download/clear functionality *@ -@inject IFileService FileService +@using JdeScoping.Core.ApiContracts +@inject IFileApiClient FileApi @inject DialogService DialogService @inject NotificationService NotificationService @@ -47,8 +48,15 @@ private async Task DownloadTemplateAsync() { - var workOrderNumbers = WorkOrders.Select(wo => wo.WorkOrderNumber).ToList(); - await FileService.DownloadTemplateAsync("workorders", workOrderNumbers); + var result = await FileApi.DownloadWorkOrdersTemplateAsync(WorkOrders.AsReadOnly()); + result.Switch( + bytes => { _ = JSRuntime.InvokeVoidAsync("downloadFile", "workorders_template.xlsx", bytes); }, + _ => { NotificationService.Notify(NotificationSeverity.Error, "Error", "Template not found."); }, + validation => { NotificationService.Notify(NotificationSeverity.Error, "Error", string.Join("; ", validation.FieldErrors.SelectMany(e => e.Value))); }, + _ => { NotificationService.Notify(NotificationSeverity.Error, "Error", "Session expired."); }, + _ => { NotificationService.Notify(NotificationSeverity.Error, "Error", "Access denied."); }, + error => { NotificationService.Notify(NotificationSeverity.Error, "Error", error.Message); } + ); } private async Task TriggerFileInput() @@ -64,19 +72,22 @@ try { using var stream = e.File.OpenReadStream(maxAllowedSize: 10 * 1024 * 1024); // 10MB max - var result = await FileService.UploadAsync("workorders", stream, e.File.Name); + var result = await FileApi.UploadWorkOrdersAsync(stream, e.File.Name); - if (result.WasSuccessful) - { - WorkOrders.Clear(); - WorkOrders.AddRange(result.Data); - await WorkOrdersChanged.InvokeAsync(WorkOrders); - NotificationService.Notify(NotificationSeverity.Success, "Upload Complete", $"Loaded {result.Data.Count} work orders."); - } - else - { - NotificationService.Notify(NotificationSeverity.Error, "Upload Failed", result.ErrorMessage); - } + result.Switch( + workOrders => + { + WorkOrders.Clear(); + WorkOrders.AddRange(workOrders); + _ = WorkOrdersChanged.InvokeAsync(WorkOrders); + NotificationService.Notify(NotificationSeverity.Success, "Upload Complete", $"Loaded {workOrders.Count} work orders."); + }, + _ => { NotificationService.Notify(NotificationSeverity.Error, "Error", "Upload endpoint not found."); }, + validation => { NotificationService.Notify(NotificationSeverity.Error, "Upload Failed", string.Join("; ", validation.FieldErrors.SelectMany(e => e.Value))); }, + _ => { NotificationService.Notify(NotificationSeverity.Error, "Error", "Session expired."); }, + _ => { NotificationService.Notify(NotificationSeverity.Error, "Error", "Access denied."); }, + error => { NotificationService.Notify(NotificationSeverity.Error, "Upload Failed", error.Message); } + ); } catch (Exception ex) {