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 *@
|
@* Item number filter panel with autocomplete and grid *@
|
||||||
@inject ILookupService LookupService
|
@using JdeScoping.Core.ApiContracts
|
||||||
@inject IFileService FileService
|
@inject ILookupApiClient LookupApi
|
||||||
|
@inject IFileApiClient FileApi
|
||||||
@inject DialogService DialogService
|
@inject DialogService DialogService
|
||||||
@inject NotificationService NotificationService
|
@inject NotificationService NotificationService
|
||||||
|
|
||||||
@@ -78,7 +79,15 @@
|
|||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(args.Filter) && args.Filter.Length >= 3)
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -117,7 +126,15 @@
|
|||||||
|
|
||||||
private async Task DownloadTemplateAsync()
|
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()
|
private async Task TriggerFileInput()
|
||||||
@@ -132,20 +149,23 @@
|
|||||||
_isUploading = true;
|
_isUploading = true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var stream = e.File.OpenReadStream(maxAllowedSize: 10 * 1024 * 1024); // 10MB max
|
using var stream = e.File.OpenReadStream(maxAllowedSize: 10 * 1024 * 1024);
|
||||||
var result = await FileService.UploadAsync<ItemViewModel>("items", stream, e.File.Name);
|
var result = await FileApi.UploadItemsAsync(stream, e.File.Name);
|
||||||
|
|
||||||
if (result.WasSuccessful)
|
result.Switch(
|
||||||
{
|
items =>
|
||||||
Items.Clear();
|
{
|
||||||
Items.AddRange(result.Data);
|
Items.Clear();
|
||||||
await ItemsChanged.InvokeAsync(Items);
|
Items.AddRange(items);
|
||||||
NotificationService.Notify(NotificationSeverity.Success, "Upload Complete", $"Loaded {result.Data.Count} items.");
|
_ = ItemsChanged.InvokeAsync(Items);
|
||||||
}
|
NotificationService.Notify(NotificationSeverity.Success, "Upload Complete", $"Loaded {items.Count} items.");
|
||||||
else
|
},
|
||||||
{
|
_ => { NotificationService.Notify(NotificationSeverity.Error, "Error", "Upload endpoint not found."); },
|
||||||
NotificationService.Notify(NotificationSeverity.Error, "Upload Failed", result.ErrorMessage);
|
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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user