73 lines
2.4 KiB
C#
73 lines
2.4 KiB
C#
using System.Text.Json;
|
|
using BimAI.Application.DTOModels;
|
|
using BimAI.Application.DTOModels.Common;
|
|
using Microsoft.AspNetCore.WebUtilities;
|
|
|
|
namespace BimAI.UI.Shared.Services;
|
|
|
|
public class InvoiceService(HttpClient httpClient)
|
|
{
|
|
private readonly HttpClient _httpClient = httpClient;
|
|
private readonly JsonSerializerOptions _jsonOptions = new()
|
|
{
|
|
PropertyNameCaseInsensitive = true
|
|
};
|
|
|
|
public async Task<PagedResult<InvoiceDto>> GetInvoiceAsync(InvoiceFilterRequest request)
|
|
{
|
|
var queryParams = new Dictionary<string, string?>
|
|
{
|
|
["page"] = request.Page.ToString(),
|
|
["pageSize"] = request.PageSize.ToString(),
|
|
};
|
|
|
|
if (!string.IsNullOrWhiteSpace(request.Search))
|
|
{
|
|
queryParams["search"] = request.Search;
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(request.ClientName))
|
|
{
|
|
queryParams["clientName"] = request.ClientName;
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(request.Type))
|
|
{
|
|
queryParams["type"] = request.Type;
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(request.DocumentNo))
|
|
{
|
|
queryParams["documentNo"] = request.DocumentNo;
|
|
}
|
|
if (request.RegisterDateFrom.HasValue)
|
|
{
|
|
queryParams["registerDateFrom"] = request.RegisterDateFrom.Value.ToString("yyyy-MM-dd");;
|
|
}
|
|
if (request.RegisterDateTo.HasValue)
|
|
{
|
|
queryParams["registerDateTo"] = request.RegisterDateTo.Value.ToString("yyyy-MM-dd");
|
|
}
|
|
if (request.SellDateFrom.HasValue)
|
|
{
|
|
queryParams["sellDateFrom"] = request.SellDateFrom.Value.ToString("yyyy-MM-dd");
|
|
}
|
|
if (request.SellDateTo.HasValue)
|
|
{
|
|
queryParams["sellDateTo"] = request.SellDateTo.Value.ToString("yyyy-MM-dd");
|
|
}
|
|
var uri = QueryHelpers.AddQueryString("api/invoice", queryParams);
|
|
|
|
var response = await _httpClient.GetAsync(uri);
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
var errorContent = await response.Content.ReadAsStringAsync();
|
|
}
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
var json = await response.Content.ReadAsStringAsync();
|
|
|
|
var result = JsonSerializer.Deserialize<PagedResult<InvoiceDto>>(json, _jsonOptions);
|
|
|
|
return result ?? new PagedResult<InvoiceDto>();
|
|
}
|
|
} |