diff --git a/NEW/src/JdeScoping.Client/Pages/SearchEdit.razor b/NEW/src/JdeScoping.Client/Pages/SearchEdit.razor index d1c39f2..7c37af9 100644 --- a/NEW/src/JdeScoping.Client/Pages/SearchEdit.razor +++ b/NEW/src/JdeScoping.Client/Pages/SearchEdit.razor @@ -5,7 +5,6 @@ @using JdeScoping.Client.Extensions @inject ISearchApiClient SearchApi @inject IHubConnectionService HubConnection -@inject IFileService FileService @inject AuthStateProvider AuthStateProvider @inject NavigationManager NavigationManager @inject DialogService DialogService diff --git a/NEW/src/JdeScoping.Client/Services/FileService.cs b/NEW/src/JdeScoping.Client/Services/FileService.cs deleted file mode 100644 index fdd3a57..0000000 --- a/NEW/src/JdeScoping.Client/Services/FileService.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System.Net.Http.Json; -using JdeScoping.Client.Models; -using JdeScoping.Core.ViewModels; -using Microsoft.JSInterop; - -namespace JdeScoping.Client.Services; - -/// -/// Handles file upload/download operations via the api/fileio endpoints. -/// Authentication is handled via cookies (sent automatically by the browser). -/// -public class FileService : IFileService -{ - private readonly HttpClient _httpClient; - private readonly IJSRuntime _jsRuntime; - - public FileService(HttpClient httpClient, IJSRuntime jsRuntime) - { - _httpClient = httpClient; - _jsRuntime = jsRuntime; - } - - public async Task DownloadTemplateAsync(string templateType, object? existingData = null) - { - try - { - // Map template type to API endpoint - var endpoint = templateType switch - { - "work-orders" or "workorders" => "api/fileio/workorders/download", - "items" or "part-numbers" => "api/fileio/items/download", - "component-lots" or "componentlots" => "api/fileio/componentlots/download", - "part-operations" or "partoperations" => "api/fileio/partoperations/download", - _ => throw new ArgumentException($"Unknown template type: {templateType}") - }; - - var fileName = templateType switch - { - "work-orders" or "workorders" => "work_order_template.xlsx", - "items" or "part-numbers" => "item_number_template.xlsx", - "component-lots" or "componentlots" => "component_lot_template.xlsx", - "part-operations" or "partoperations" => "item_operations_mis_template.xlsx", - _ => $"{templateType}_template.xlsx" - }; - - // POST with existing data to get the Excel file - var response = await _httpClient.PostAsJsonAsync(endpoint, existingData); - - if (response.IsSuccessStatusCode) - { - var bytes = await response.Content.ReadAsByteArrayAsync(); - await _jsRuntime.InvokeVoidAsync("downloadFile", fileName, bytes); - } - else - { - Console.WriteLine($"Failed to download template: {response.StatusCode}"); - } - } - catch (Exception ex) - { - Console.WriteLine($"Failed to download template: {ex.Message}"); - } - } - - public async Task DownloadPartNumberTemplateAsync(List? existingItems = null) - { - await DownloadTemplateAsync("items", existingItems); - } - - public async Task> UploadAsync(string uploadType, Stream fileStream, string fileName) - { - try - { - // Map upload type to API endpoint - var endpoint = uploadType switch - { - "work-orders" or "workorders" => "api/fileio/workorders/upload", - "items" or "part-numbers" => "api/fileio/items/upload", - "component-lots" or "componentlots" => "api/fileio/componentlots/upload", - "part-operations" or "partoperations" => "api/fileio/partoperations/upload", - _ => throw new ArgumentException($"Unknown upload type: {uploadType}") - }; - - using var content = new MultipartFormDataContent(); - using var streamContent = new StreamContent(fileStream); - content.Add(streamContent, "file", fileName); - - var response = await _httpClient.PostAsync(endpoint, content); - - if (response.IsSuccessStatusCode) - { - var result = await response.Content.ReadFromJsonAsync>(); - return result ?? new UploadResult - { - WasSuccessful = false, - ErrorMessage = "Invalid response from server" - }; - } - - return new UploadResult - { - WasSuccessful = false, - ErrorMessage = $"Upload failed: {response.StatusCode}" - }; - } - catch (Exception ex) - { - return new UploadResult - { - WasSuccessful = false, - ErrorMessage = $"Upload failed: {ex.Message}" - }; - } - } -} diff --git a/NEW/src/JdeScoping.Client/Services/IFileService.cs b/NEW/src/JdeScoping.Client/Services/IFileService.cs deleted file mode 100644 index c6ae2fe..0000000 --- a/NEW/src/JdeScoping.Client/Services/IFileService.cs +++ /dev/null @@ -1,35 +0,0 @@ -using JdeScoping.Client.Models; -using JdeScoping.Core.ViewModels; - -namespace JdeScoping.Client.Services; - -/// -/// Service for file upload/download operations. -/// -public interface IFileService -{ - /// - /// Downloads the work order template file. - /// - Task DownloadTemplateAsync(string templateType, object? existingData = null); - - /// - /// Downloads the part number template file. - /// - Task DownloadPartNumberTemplateAsync(List? existingItems = null); - - /// - /// Uploads a file and returns parsed data. - /// - Task> UploadAsync(string uploadType, Stream fileStream, string fileName); -} - -/// -/// Result of a file upload operation. -/// -public class UploadResult -{ - public bool WasSuccessful { get; set; } - public string? ErrorMessage { get; set; } - public List Data { get; set; } = []; -} diff --git a/NEW/src/JdeScoping.Client/Services/ILookupService.cs b/NEW/src/JdeScoping.Client/Services/ILookupService.cs deleted file mode 100644 index 0178a7e..0000000 --- a/NEW/src/JdeScoping.Client/Services/ILookupService.cs +++ /dev/null @@ -1,30 +0,0 @@ -using JdeScoping.Client.Models; -using JdeScoping.Core.ViewModels; - -namespace JdeScoping.Client.Services; - -/// -/// Service for lookup/autocomplete API operations. -/// -public interface ILookupService -{ - /// - /// Finds items matching the search term. - /// - Task> FindItemsAsync(string searchTerm); - - /// - /// Finds profit centers matching the search term. - /// - Task> FindProfitCentersAsync(string searchTerm); - - /// - /// Finds work centers matching the search term. - /// - Task> FindWorkCentersAsync(string searchTerm); - - /// - /// Finds operators matching the search term. - /// - Task> FindOperatorsAsync(string searchTerm); -} diff --git a/NEW/src/JdeScoping.Client/Services/ISearchService.cs b/NEW/src/JdeScoping.Client/Services/ISearchService.cs deleted file mode 100644 index 02f42aa..0000000 --- a/NEW/src/JdeScoping.Client/Services/ISearchService.cs +++ /dev/null @@ -1,39 +0,0 @@ -using JdeScoping.Client.Models; - -namespace JdeScoping.Client.Services; - -/// -/// Service for search-related API operations. -/// -public interface ISearchService -{ - /// - /// Gets all searches for the current user. - /// - Task> GetUserSearchesAsync(); - - /// - /// Gets a specific search by ID. - /// - Task GetSearchAsync(int id); - - /// - /// Copies an existing search to create a new one. - /// - Task CopySearchAsync(int id); - - /// - /// Saves and submits a search. - /// - Task SaveSearchAsync(SearchViewModel search); - - /// - /// Gets all searches in the queue. - /// - Task> GetQueueAsync(); - - /// - /// Downloads the results for a completed search. - /// - Task DownloadResultsAsync(int id); -} diff --git a/NEW/src/JdeScoping.Client/Services/LookupService.cs b/NEW/src/JdeScoping.Client/Services/LookupService.cs deleted file mode 100644 index 8a05a7d..0000000 --- a/NEW/src/JdeScoping.Client/Services/LookupService.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System.Net.Http.Json; -using JdeScoping.Client.Models; -using JdeScoping.Core.ViewModels; - -namespace JdeScoping.Client.Services; - -/// -/// Handles lookup/autocomplete API calls. -/// Authentication is handled via cookies (sent automatically by the browser). -/// -public class LookupService : ILookupService -{ - private readonly HttpClient _httpClient; - - public LookupService(HttpClient httpClient) - { - _httpClient = httpClient; - } - - public async Task> FindItemsAsync(string searchTerm) - { - if (string.IsNullOrEmpty(searchTerm) || searchTerm.Length < 3) - { - return []; - } - - try - { - var result = await _httpClient.GetFromJsonAsync>( - $"api/lookup/items?q={Uri.EscapeDataString(searchTerm)}"); - return result ?? []; - } - catch (Exception ex) - { - Console.WriteLine($"Failed to find items: {ex.Message}"); - return []; - } - } - - public async Task> FindProfitCentersAsync(string searchTerm) - { - if (string.IsNullOrEmpty(searchTerm) || searchTerm.Length < 3) - { - return []; - } - - try - { - var result = await _httpClient.GetFromJsonAsync>( - $"api/lookup/profit-centers?q={Uri.EscapeDataString(searchTerm)}"); - return result ?? []; - } - catch (Exception ex) - { - Console.WriteLine($"Failed to find profit centers: {ex.Message}"); - return []; - } - } - - public async Task> FindWorkCentersAsync(string searchTerm) - { - if (string.IsNullOrEmpty(searchTerm) || searchTerm.Length < 3) - { - return []; - } - - try - { - var result = await _httpClient.GetFromJsonAsync>( - $"api/lookup/work-centers?q={Uri.EscapeDataString(searchTerm)}"); - return result ?? []; - } - catch (Exception ex) - { - Console.WriteLine($"Failed to find work centers: {ex.Message}"); - return []; - } - } - - public async Task> FindOperatorsAsync(string searchTerm) - { - if (string.IsNullOrEmpty(searchTerm) || searchTerm.Length < 3) - { - return []; - } - - try - { - var result = await _httpClient.GetFromJsonAsync>( - $"api/lookup/operators?q={Uri.EscapeDataString(searchTerm)}"); - return result ?? []; - } - catch (Exception ex) - { - Console.WriteLine($"Failed to find operators: {ex.Message}"); - return []; - } - } -} diff --git a/NEW/src/JdeScoping.Client/Services/SearchService.cs b/NEW/src/JdeScoping.Client/Services/SearchService.cs deleted file mode 100644 index 7e70521..0000000 --- a/NEW/src/JdeScoping.Client/Services/SearchService.cs +++ /dev/null @@ -1,129 +0,0 @@ -using System.Net.Http.Json; -using JdeScoping.Client.Models; - -namespace JdeScoping.Client.Services; - -/// -/// Handles search-related API calls. -/// Authentication is handled via cookies (sent automatically by the browser). -/// -public class SearchService : ISearchService -{ - private readonly HttpClient _httpClient; - - public SearchService(HttpClient httpClient) - { - _httpClient = httpClient; - } - - public async Task> GetUserSearchesAsync() - { - try - { - var result = await _httpClient.GetFromJsonAsync>("api/search"); - return result ?? []; - } - catch (Exception ex) - { - Console.WriteLine($"Failed to get searches: {ex.Message}"); - return []; - } - } - - public async Task GetSearchAsync(int id) - { - try - { - return await _httpClient.GetFromJsonAsync($"api/search/{id}"); - } - catch (Exception ex) - { - Console.WriteLine($"Failed to get search {id}: {ex.Message}"); - return null; - } - } - - public async Task CopySearchAsync(int id) - { - try - { - return await _httpClient.GetFromJsonAsync($"api/search/{id}/copy"); - } - catch (Exception ex) - { - Console.WriteLine($"Failed to copy search {id}: {ex.Message}"); - return null; - } - } - - public async Task SaveSearchAsync(SearchViewModel search) - { - try - { - var response = await _httpClient.PostAsJsonAsync("api/search", new - { - search.Name, - search.UserName, - Criteria = new - { - MinimumDT = search.Criteria.MinimumDt, - MaximumDT = search.Criteria.MaximumDt, - WorkOrders = search.Criteria.WorkOrders.Select(wo => new { wo.WorkOrderNumber }), - Items = search.Criteria.Items.Select(i => new { i.ItemNumber }), - ProfitCenters = search.Criteria.ProfitCenters.Select(pc => new { pc.Code }), - WorkCenters = search.Criteria.WorkCenters.Select(wc => new { wc.Code }), - ComponentLots = search.Criteria.ComponentLots.Select(cl => new { cl.LotNumber, cl.ItemNumber }), - Operators = search.Criteria.Operators.Select(op => new { op.AddressNumber, UserID = op.UserId }), - PartOperations = search.Criteria.PartOperations.Select(po => new - { - po.ItemNumber, - po.OperationNumber, - po.MisNumber, - po.MisRevision - }), - search.Criteria.ExtractMisData - } - }); - - if (response.IsSuccessStatusCode) - { - return await response.Content.ReadFromJsonAsync(); - } - - Console.WriteLine($"Failed to save search: {response.StatusCode}"); - return null; - } - catch (Exception ex) - { - Console.WriteLine($"Failed to save search: {ex.Message}"); - return null; - } - } - - public async Task> GetQueueAsync() - { - try - { - var result = await _httpClient.GetFromJsonAsync>("api/search/queue"); - return result ?? []; - } - catch (Exception ex) - { - Console.WriteLine($"Failed to get queue: {ex.Message}"); - return []; - } - } - - public async Task DownloadResultsAsync(int id) - { - try - { - return await _httpClient.GetByteArrayAsync($"api/search/{id}/results"); - } - catch (Exception ex) - { - Console.WriteLine($"Failed to download results for {id}: {ex.Message}"); - return null; - } - } -}