Files
DocumentService/DocumentService.Client/Clients/PdfValidationClient.cs
TekH 2c98558131 Refactor DTOs and namespaces for maintainability
Consolidated DTOs under `DocumentService.Application.Common.DTOs.Requests`
to centralize and align them with the application layer. Introduced
`PdfBase64RequestBase` to encapsulate shared properties, reducing
redundancy across request DTOs. Updated controllers, clients, and tests
to use the new DTO structure. Removed redundant DTOs and cleaned up
unused namespaces and comments. Improved documentation and ensured
consistent naming conventions across the codebase.
2026-08-31 01:19:52 +02:00

70 lines
2.4 KiB
C#

using DocumentService.Application.Common.DTOs;
using DocumentService.Client.Interfaces;
using DocumentService.Application.Common.DTOs.Requests;
using Microsoft.Extensions.Logging;
using System.Net.Http;
namespace DocumentService.Client.Clients;
/// <summary>
/// Implementation of PDF validation client.
/// </summary>
public class PdfValidationClient(HttpClient httpClient, ILogger<PdfValidationClient> logger) : BaseDocumentClient(httpClient, logger), IPdfValidationClient
{
/// <inheritdoc />
public async Task<PdfValidationResult> ValidatePdfAsync(Stream pdfStream, CancellationToken cancellationToken = default)
{
var result = await SendMultipartAsync<PdfValidationResult>(
"/api/pdf/validation/validate",
pdfStream,
"document.pdf",
cancellationToken);
return result ?? throw new InvalidOperationException("API returned null response");
}
/// <inheritdoc />
public async Task<PdfValidationResult> ValidatePdfAsync(byte[] pdfBytes, CancellationToken cancellationToken = default)
{
var request = new ValidatePdfBase64Request
{
Base64Pdf = ToBase64(pdfBytes)
};
var result = await SendJsonAsync<ValidatePdfBase64Request, PdfValidationResult>(
"/api/pdf/validation/validate",
request,
cancellationToken);
return result ?? throw new InvalidOperationException("API returned null response");
}
/// <inheritdoc />
public async Task<PdfAValidationResult> ValidatePdfAAsync(Stream pdfStream, CancellationToken cancellationToken = default)
{
var result = await SendMultipartAsync<PdfAValidationResult>(
"/api/pdf/validation/validate-pdfa",
pdfStream,
"document.pdf",
cancellationToken);
return result ?? throw new InvalidOperationException("API returned null response");
}
/// <inheritdoc />
public async Task<PdfAValidationResult> ValidatePdfAAsync(byte[] pdfBytes, CancellationToken cancellationToken = default)
{
var request = new ValidatePdfABase64Request
{
Base64Pdf = ToBase64(pdfBytes)
};
var result = await SendJsonAsync<ValidatePdfABase64Request, PdfAValidationResult>(
"/api/pdf/validation/validate-pdfa",
request,
cancellationToken);
return result ?? throw new InvalidOperationException("API returned null response");
}
}