DataInbox list
This commit is contained in:
49
DiunaBI.UI.Shared/Services/DataInboxService.cs
Normal file
49
DiunaBI.UI.Shared/Services/DataInboxService.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
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 DataInboxService
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
public DataInboxService(HttpClient httpClient)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
}
|
||||
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
public async Task<PagedResult<DataInboxDto>> GetDataInboxAsync(DataInboxFilterRequest filterRequest)
|
||||
{
|
||||
// Calculate start index from page number (page 1 = start 0, page 2 = start 50, etc.)
|
||||
var start = (filterRequest.Page - 1) * filterRequest.PageSize;
|
||||
var query = $"DataInbox/GetAll?start={start}&limit={filterRequest.PageSize}";
|
||||
|
||||
if (!string.IsNullOrEmpty(filterRequest.Search))
|
||||
query += $"&name={Uri.EscapeDataString(filterRequest.Search)}";
|
||||
|
||||
var response = await _httpClient.GetAsync(query);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonSerializer.Deserialize<PagedResult<DataInboxDto>>(json, _jsonOptions);
|
||||
|
||||
return result ?? new PagedResult<DataInboxDto>();
|
||||
}
|
||||
|
||||
public async Task<DataInboxDto?> GetDataInboxByIdAsync(Guid id)
|
||||
{
|
||||
var response = await _httpClient.GetAsync($"DataInbox/{id}");
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return null;
|
||||
|
||||
return await response.Content.ReadFromJsonAsync<DataInboxDto>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user