diff --git a/NEW/src/JdeScoping.Client/Components/FilterPanels/ComponentLotFilterPanel.razor b/NEW/src/JdeScoping.Client/Components/FilterPanels/ComponentLotFilterPanel.razor index 4711962..606e44f 100644 --- a/NEW/src/JdeScoping.Client/Components/FilterPanels/ComponentLotFilterPanel.razor +++ b/NEW/src/JdeScoping.Client/Components/FilterPanels/ComponentLotFilterPanel.razor @@ -1,5 +1,7 @@ @* Component lot filter panel with upload/download/clear functionality *@ -@inject IFileService FileService +@using JdeScoping.Core.ApiContracts +@using JdeScoping.Core.ViewModels +@inject IFileApiClient FileApi @inject DialogService DialogService @inject NotificationService NotificationService @@ -47,8 +49,16 @@ private async Task DownloadTemplateAsync() { - var lotData = ComponentLots.Select(cl => new { cl.LotNumber, cl.ItemNumber }).ToList(); - await FileService.DownloadTemplateAsync("componentlots", lotData); + var lotData = ComponentLots.Select(cl => new LotViewModel { LotNumber = cl.LotNumber, ItemNumber = cl.ItemNumber }).ToList().AsReadOnly(); + var result = await FileApi.DownloadComponentLotsTemplateAsync(lotData); + result.Switch( + bytes => { _ = JSRuntime.InvokeVoidAsync("downloadFile", "componentlots_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 +74,22 @@ try { using var stream = e.File.OpenReadStream(maxAllowedSize: 10 * 1024 * 1024); // 10MB max - var result = await FileService.UploadAsync("componentlots", stream, e.File.Name); + var result = await FileApi.UploadComponentLotsAsync(stream, e.File.Name); - if (result.WasSuccessful) - { - ComponentLots.Clear(); - ComponentLots.AddRange(result.Data); - await ComponentLotsChanged.InvokeAsync(ComponentLots); - NotificationService.Notify(NotificationSeverity.Success, "Upload Complete", $"Loaded {result.Data.Count} component lots."); - } - else - { - NotificationService.Notify(NotificationSeverity.Error, "Upload Failed", result.ErrorMessage); - } + result.Switch( + lots => + { + ComponentLots.Clear(); + ComponentLots.AddRange(lots.Select(l => new ComponentLotViewModel { LotNumber = l.LotNumber, ItemNumber = l.ItemNumber })); + _ = ComponentLotsChanged.InvokeAsync(ComponentLots); + NotificationService.Notify(NotificationSeverity.Success, "Upload Complete", $"Loaded {lots.Count} component lots."); + }, + _ => { 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) {