feat: Add CheckPdfAttachments feature - Application layer
- Add CheckPdfAttachmentsQuery with dual input support (byte[] + Base64) - Add CheckPdfAttachmentsQueryHandler with IPdfProcessor integration - Add CheckPdfAttachmentsQueryValidator with FluentValidation rules - Add AttachmentCheckResult DTO for API response - Handler converts byte[] → MemoryStream for IPdfProcessor.CheckAttachmentsAsync() - AutoMapper maps AttachmentInfo → AttachmentCheckResult
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace DocumentOperator.Application.CheckPdfAttachments.Queries;
|
||||
|
||||
/// <summary>
|
||||
/// Validator for CheckPdfAttachmentsQuery
|
||||
/// Ensures exactly one input type (PdfBytes OR Base64Pdf) is provided
|
||||
/// </summary>
|
||||
public class CheckPdfAttachmentsQueryValidator : AbstractValidator<CheckPdfAttachmentsQuery>
|
||||
{
|
||||
public CheckPdfAttachmentsQueryValidator()
|
||||
{
|
||||
// Rule 1: Exactly ONE input must be provided (XOR logic)
|
||||
RuleFor(x => x)
|
||||
.Must(x => (x.PdfBytes != null && x.PdfBytes.Length > 0) ^
|
||||
(!string.IsNullOrWhiteSpace(x.Base64Pdf)))
|
||||
.WithMessage("Either PdfBytes or Base64Pdf must be provided, but not both");
|
||||
|
||||
// Rule 2: Base64 format validation (if provided)
|
||||
RuleFor(x => x.Base64Pdf)
|
||||
.Must(BeValidBase64)
|
||||
.When(x => !string.IsNullOrWhiteSpace(x.Base64Pdf))
|
||||
.WithMessage("Base64Pdf must be a valid Base64 string");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates if a string is a valid Base64 format
|
||||
/// </summary>
|
||||
private bool BeValidBase64(string? base64)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(base64))
|
||||
return true; // Skip validation if null/empty (handled by Rule 1)
|
||||
|
||||
try
|
||||
{
|
||||
Convert.FromBase64String(base64);
|
||||
return true;
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user