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.
This commit is contained in:
@@ -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<ItemViewModel>("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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user