Removed detailed description of the `raw` parameter in XML documentation for two methods in `SwissQrCodeController`. Updated `<returns>` tag to simplify the explanation by removing conditional details based on the `raw` parameter. These changes affect methods handling multipart/form-data PDF input and Base64 JSON input.
89 lines
3.9 KiB
C#
89 lines
3.9 KiB
C#
using DocumentOperator.Application.Common.DTOs;
|
|
using DocumentOperator.Application.SwissQrCode.Queries;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace DocumentOperator.API.Controllers;
|
|
|
|
/// <summary>
|
|
/// Swiss QR Code extraction operations
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("api/pdf/qr-code")]
|
|
[Produces("application/json")]
|
|
public class SwissQrCodeController(IMediator Mediator) : ControllerBase
|
|
{
|
|
/// <summary>
|
|
/// Extracts Swiss QR Code from the last page of a PDF document (multipart/form-data)
|
|
/// </summary>
|
|
/// <param name="file">PDF file containing Swiss QR Code</param>
|
|
/// <param name="raw"></param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>Swiss QR Code data (IBAN, amount, creditor, debtor, reference, etc.)</returns>
|
|
/// <response code="200">Swiss QR Code extracted successfully</response>
|
|
/// <response code="400">Invalid PDF or file format</response>
|
|
/// <response code="404">No Swiss QR Code found on the last page</response>
|
|
/// <response code="500">Internal server error during extraction</response>
|
|
[HttpPost("extract-swiss")]
|
|
[Consumes("multipart/form-data")]
|
|
[ProducesResponseType(typeof(SwissQrCodeExtractionResult), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
|
|
public async Task<IActionResult> ExtractFromFile(
|
|
IFormFile file,
|
|
[FromQuery] bool raw = false,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
if (file.Length == 0)
|
|
return BadRequest(new ProblemDetails
|
|
{
|
|
Title = "Invalid file",
|
|
Detail = "File is required and cannot be empty",
|
|
Status = StatusCodes.Status400BadRequest
|
|
});
|
|
|
|
// Convert IFormFile to byte array
|
|
using var memoryStream = new MemoryStream();
|
|
await file.CopyToAsync(memoryStream, cancellationToken);
|
|
byte[] pdfBytes = memoryStream.ToArray();
|
|
|
|
// Direct pass-through to MediatR
|
|
var query = new ExtractSwissQrCodeQuery
|
|
{
|
|
PdfBytes = pdfBytes
|
|
};
|
|
var result = await Mediator.Send(query, cancellationToken);
|
|
|
|
return Ok(raw ? result.RawLines : result.Bill);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Extracts Swiss QR Code from the last page of a PDF document (Base64 JSON)
|
|
/// </summary>
|
|
/// <param name="query">References array + PDF as Base64 string</param>
|
|
/// <param name="raw"></param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>Swiss QR Code data (IBAN, amount, creditor, debtor, reference, etc.)</returns>
|
|
/// <response code="200">Swiss QR Code extracted successfully</response>
|
|
/// <response code="400">Invalid PDF or Base64 format</response>
|
|
/// <response code="404">No Swiss QR Code found on the last page</response>
|
|
/// <response code="500">Internal server error during extraction</response>
|
|
[HttpPost("extract-swiss")]
|
|
[Consumes("application/json")]
|
|
[ProducesResponseType(typeof(SwissQrCodeExtractionResult), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
|
|
public async Task<IActionResult> ExtractFromBase64(
|
|
[FromBody] ExtractSwissQrCodeQuery query,
|
|
[FromQuery] bool raw = false,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
// Direct pass-through to MediatR
|
|
var result = await Mediator.Send(query, cancellationToken);
|
|
|
|
return Ok(raw ? result.RawLines : result.Bill);
|
|
}
|
|
}
|