WIP: frontend refactor

This commit is contained in:
Michał Zieliński
2025-11-06 10:20:00 +01:00
parent 5bee3912f1
commit 7f04cab0d9
38 changed files with 1254 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
using System.Net.Http.Json;
using System.Text.Json;
using DiunaBI.Application.DTOModels;
using DiunaBI.Application.DTOModels.Common;
namespace DiunaBI.UI.Shared.Services;
public class LayerService
{
private readonly HttpClient _httpClient;
public LayerService(HttpClient httpClient)
{
_httpClient = httpClient;
}
private readonly JsonSerializerOptions _jsonOptions = new()
{
PropertyNameCaseInsensitive = true
};
public async Task<PagedResult<LayerDto>> GetLayersAsync(LayerFilterRequest filterRequest)
{
var query = $"/api/Layers?start={filterRequest.Page}&limit={filterRequest.Page}";
if (!string.IsNullOrEmpty(filterRequest.Search))
query += $"&name={Uri.EscapeDataString(filterRequest.Search)}";
/*
if (type.HasValue)
query += $"&type={type.Value}";
*/
var response = await _httpClient.GetAsync(query);
response.EnsureSuccessStatusCode();
var json = await response.Content.ReadAsStringAsync();
var result = JsonSerializer.Deserialize<PagedResult<LayerDto>>(json, _jsonOptions);
return result ?? new PagedResult<LayerDto>();
}
public async Task<LayerDto?> GetLayerByIdAsync(Guid id)
{
var response = await _httpClient.GetAsync($"/api/Layers/{id}");
if (!response.IsSuccessStatusCode)
return null;
return await response.Content.ReadFromJsonAsync<LayerDto>();
}
public async Task<bool> UpdateRecordsAsync(Guid layerId, List<RecordDto> records)
{
// TODO: Implement if needed - backend doesn't have PUT endpoint yet
// For now we don't need it for read-only view
return await Task.FromResult(false);
}
}