This commit implements a complete rebranding of the project: - Updated all namespaces from `DocumentOperator` to `DocumentService`. - Renamed file paths, embedded resources, and test data references. - Updated configuration keys, logging paths, and Redis instance names. - Revised documentation to reflect the new project name. - Modified project and solution files to align with the new structure. - Updated class names, DTOs, commands, queries, and handlers. - Adjusted middleware, controllers, and API endpoints. - Updated Swagger metadata and API titles to `DocumentService API`. - Refactored test namespaces, resource paths, and embedded resources. - Updated build and deployment configurations for the new name. - Replaced all references to `DocumentOperator` in comments and literals. These changes ensure consistency across the codebase and documentation.
63 lines
2.1 KiB
C#
63 lines
2.1 KiB
C#
using DocumentService.Application.Common.Configuration;
|
|
using DocumentService.Application.Common.DTOs;
|
|
using DocumentService.Application.Common.Interfaces;
|
|
using MediatR;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace DocumentService.Application.HasZugferd.Queries;
|
|
|
|
/// <summary>
|
|
/// Query for checking if PDF contains ZUGFeRD XML attachment
|
|
/// </summary>
|
|
public record HasZugferdQuery : IRequest<ZugferdCheckResult>
|
|
{
|
|
/// <summary>
|
|
/// PDF as stream (caller is responsible for disposal)
|
|
/// </summary>
|
|
public required Stream PdfStream { get; init; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handler for HasZugferdQuery
|
|
/// Checks if PDF contains ZUGFeRD/Factur-X XML attachment
|
|
/// </summary>
|
|
public class HasZugferdQueryHandler(
|
|
IPdfProcessor pdfProcessor,
|
|
IOptions<ZugferdSettings> settings)
|
|
: IRequestHandler<HasZugferdQuery, ZugferdCheckResult>
|
|
{
|
|
private readonly ZugferdSettings _settings = settings.Value;
|
|
|
|
/// <summary>
|
|
/// Checks if PDF contains ZUGFeRD XML and returns metadata
|
|
/// </summary>
|
|
public async Task<ZugferdCheckResult> Handle(HasZugferdQuery request, CancellationToken cancellationToken)
|
|
{
|
|
// Get all attachments
|
|
var attachmentInfo = await pdfProcessor.CheckAttachmentsAsync(request.PdfStream);
|
|
|
|
// Check for ZUGFeRD/Factur-X XML files using configured names and patterns
|
|
var zugferdAttachment = attachmentInfo.Attachments.FirstOrDefault(a =>
|
|
_settings.ZugferdFileNames.Any(name =>
|
|
a.FileName.Equals(name, StringComparison.OrdinalIgnoreCase)) ||
|
|
_settings.ZugferdFileNamePatterns.Any(pattern =>
|
|
a.FileName.Contains(pattern, StringComparison.OrdinalIgnoreCase)));
|
|
|
|
if (zugferdAttachment != null)
|
|
{
|
|
return new ZugferdCheckResult
|
|
{
|
|
HasZugferd = true,
|
|
ZugferdFileName = zugferdAttachment.FileName,
|
|
ZugferdFileSize = zugferdAttachment.SizeBytes,
|
|
ZugferdMimeType = zugferdAttachment.MimeType
|
|
};
|
|
}
|
|
|
|
return new ZugferdCheckResult
|
|
{
|
|
HasZugferd = false
|
|
};
|
|
}
|
|
}
|