From a6348c42681301a79173acf9dbd682e9889183c0 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Tue, 6 Jan 2026 10:30:20 -0500 Subject: [PATCH] feat(client): migrate ItemNumberFilterPanel to API clients Update ItemNumberFilterPanel.razor to use ILookupApiClient and IFileApiClient instead of legacy ILookupService and IFileService interfaces. All methods now use the result.Switch() pattern for proper ApiResult error handling. --- .../FilterPanels/ItemNumberFilterPanel.razor | 54 +++++++++++++------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/NEW/src/JdeScoping.Client/Components/FilterPanels/ItemNumberFilterPanel.razor b/NEW/src/JdeScoping.Client/Components/FilterPanels/ItemNumberFilterPanel.razor index e296d66..31fa397 100644 --- a/NEW/src/JdeScoping.Client/Components/FilterPanels/ItemNumberFilterPanel.razor +++ b/NEW/src/JdeScoping.Client/Components/FilterPanels/ItemNumberFilterPanel.razor @@ -1,6 +1,7 @@ @* Item number filter panel with autocomplete and grid *@ -@inject ILookupService LookupService -@inject IFileService FileService +@using JdeScoping.Core.ApiContracts +@inject ILookupApiClient LookupApi +@inject IFileApiClient FileApi @inject DialogService DialogService @inject NotificationService NotificationService @@ -78,7 +79,15 @@ { if (!string.IsNullOrEmpty(args.Filter) && args.Filter.Length >= 3) { - _searchResults = await LookupService.FindItemsAsync(args.Filter); + var result = await LookupApi.FindItemsAsync(args.Filter); + result.Switch( + items => { _searchResults = items.ToList(); }, + _ => { _searchResults = []; }, + _ => { _searchResults = []; }, + _ => { _searchResults = []; }, + _ => { _searchResults = []; }, + _ => { _searchResults = []; } + ); } else { @@ -117,7 +126,15 @@ private async Task DownloadTemplateAsync() { - await FileService.DownloadTemplateAsync("items", Items); + var result = await FileApi.DownloadItemsTemplateAsync(Items.AsReadOnly()); + result.Switch( + bytes => { _ = JSRuntime.InvokeVoidAsync("downloadFile", "items_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() @@ -132,20 +149,23 @@ _isUploading = true; try { - using var stream = e.File.OpenReadStream(maxAllowedSize: 10 * 1024 * 1024); // 10MB max - var result = await FileService.UploadAsync("items", stream, e.File.Name); + using var stream = e.File.OpenReadStream(maxAllowedSize: 10 * 1024 * 1024); + var result = await FileApi.UploadItemsAsync(stream, e.File.Name); - if (result.WasSuccessful) - { - Items.Clear(); - Items.AddRange(result.Data); - await ItemsChanged.InvokeAsync(Items); - NotificationService.Notify(NotificationSeverity.Success, "Upload Complete", $"Loaded {result.Data.Count} items."); - } - else - { - NotificationService.Notify(NotificationSeverity.Error, "Upload Failed", result.ErrorMessage); - } + result.Switch( + items => + { + Items.Clear(); + Items.AddRange(items); + _ = ItemsChanged.InvokeAsync(Items); + NotificationService.Notify(NotificationSeverity.Success, "Upload Complete", $"Loaded {items.Count} items."); + }, + _ => { 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) {