Files
DocumentService/DocumentService.Client/Clients/SwissQrCodeClient.cs
TekH 75bea9ef29 Refactor DTOs and tests; add framework-specific handling
Refactored the codebase to use shared DTOs from `DocumentService.Application.Common.DTOs`, removing inline DTO definitions in client interfaces and tests. Introduced conditional compilation to handle framework-specific differences in DTOs and handlers.

Updated test cases to align with the new DTO structures, including `SwissQrCodeExtractionResult`, `PdfValidationResult`, and `ZugferdExtractionResult`. Adjusted test data to match updated DTO properties.

Cleaned up solution and project files, ensuring proper references and organization. Removed unused files and fixed project references in `DocumentService.Tests.csproj`. Improved maintainability and consistency across the codebase.
2026-08-31 00:54:38 +02:00

46 lines
1.6 KiB
C#

using DocumentService.Application.Common.DTOs;
using DocumentService.Client.Interfaces;
using DocumentService.Client.Models.Requests;
using Microsoft.Extensions.Logging;
using System.Net.Http;
namespace DocumentService.Client.Clients;
/// <summary>
/// Implementation of Swiss QR Code extraction client.
/// </summary>
public class SwissQrCodeClient(HttpClient httpClient, ILogger<SwissQrCodeClient> logger) : BaseDocumentClient(httpClient, logger), ISwissQrCodeClient
{
/// <inheritdoc />
public async Task<SwissQrCodeExtractionResult> ExtractSwissQrCodeAsync(Stream pdfStream, bool raw = false, CancellationToken cancellationToken = default)
{
var endpoint = $"/api/pdf/qr-code/extract-swiss?raw={raw}";
var result = await SendMultipartAsync<SwissQrCodeExtractionResult>(
endpoint,
pdfStream,
"document.pdf",
cancellationToken);
return result ?? throw new InvalidOperationException("API returned null response");
}
/// <inheritdoc />
public async Task<SwissQrCodeExtractionResult> ExtractSwissQrCodeAsync(byte[] pdfBytes, bool raw = false, CancellationToken cancellationToken = default)
{
var endpoint = $"/api/pdf/qr-code/extract-swiss?raw={raw}";
var request = new ExtractSwissQrCodeBase64Request
{
Base64Pdf = ToBase64(pdfBytes)
};
var result = await SendJsonAsync<ExtractSwissQrCodeBase64Request, SwissQrCodeExtractionResult>(
endpoint,
request,
cancellationToken);
return result ?? throw new InvalidOperationException("API returned null response");
}
}