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) {