refactor: Update Application layer for Codecrete Bill integration
- Change SwissQrCodeExtractionResult to use Bill + RawLines - Update ISwissQrCodeProcessor to return tuple (Bill, string[]) - Add Codecrete.SwissQRBill.Generator v3.4.0 package reference - Update ExtractSwissQrCodeQuery handler to use AutoMapper for Bill->DTO mapping - Remove References property from query (not needed for QR extraction)
This commit is contained in:
@@ -19,11 +19,6 @@ public record ExtractSwissQrCodeQuery : IRequest<SwissQrCodeExtractionResult>
|
||||
/// PDF as Base64 string (API clients)
|
||||
/// </summary>
|
||||
public string? Base64Pdf { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional reference strings (passed through to response for external tracking)
|
||||
/// </summary>
|
||||
public IReadOnlyList<string>? References { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -34,23 +29,24 @@ public class ExtractSwissQrCodeQueryHandler(ISwissQrCodeProcessor qrCodeProcesso
|
||||
: IRequestHandler<ExtractSwissQrCodeQuery, SwissQrCodeExtractionResult>
|
||||
{
|
||||
/// <summary>
|
||||
/// Extracts and parses Swiss QR Code from the last page of the PDF
|
||||
/// Extracts and parses Swiss QR Code from the PDF (default: scans all pages starting with last)
|
||||
/// Returns both parsed Bill DTO and raw QR text lines
|
||||
/// </summary>
|
||||
public async Task<SwissQrCodeExtractionResult> Handle(ExtractSwissQrCodeQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Use byte[] if available, otherwise convert Base64
|
||||
byte[] pdfBytes = request.PdfBytes ?? Convert.FromBase64String(request.Base64Pdf!);
|
||||
|
||||
// Extract and parse Swiss QR Code from last page (can throw PdfProcessingException or QrCodeNotFoundException)
|
||||
var qrCodeData = await qrCodeProcessor.ExtractSwissQrCodeAsync(pdfBytes, cancellationToken);
|
||||
// Extract: returns (Bill, RawLines)
|
||||
var (bill, rawLines) = await qrCodeProcessor.ExtractSwissQrCodeAsync(pdfBytes, pageNumbers: null, cancellationToken);
|
||||
|
||||
// Map domain value object to DTO using AutoMapper
|
||||
var qrCodeDto = mapper.Map<SwissQrCodeDataDto>(qrCodeData);
|
||||
// Map Codecrete Bill to DTO using AutoMapper
|
||||
var billDto = mapper.Map<SwissQrBillDto>(bill);
|
||||
|
||||
// Return references (passed through) + QR code data
|
||||
// Return references (passed through) + Bill DTO + raw lines
|
||||
return new SwissQrCodeExtractionResult(
|
||||
References: request.References ?? [],
|
||||
QrCodeData: qrCodeDto
|
||||
Bill: billDto,
|
||||
RawLines: rawLines
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user