feat: Add specialized client implementations for PDF operations
This commit is contained in:
68
DocumentService.Client/Clients/PdfValidationClient.cs
Normal file
68
DocumentService.Client/Clients/PdfValidationClient.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using DocumentService.Client.Interfaces;
|
||||
using DocumentService.Client.Models.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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user