refactor: Move DTOs from Domain to Application layer
- Move PdfMetadata, PdfAMetadata from Domain.Models.ValueObjects to Application.Common.DTOs - Move AttachmentInfo, AttachmentMetadata from Domain.Models.ValueObjects to Application.Common.DTOs - Reason: DTOs belong in Application layer, Domain should have zero external dependencies (Clean Architecture)
This commit is contained in:
60
DocumentOperator.Application/Common/DTOs/AttachmentInfo.cs
Normal file
60
DocumentOperator.Application/Common/DTOs/AttachmentInfo.cs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
namespace DocumentOperator.Application.Common.DTOs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents complete attachment information for a PDF document.
|
||||||
|
/// Immutable value object containing attachment presence flag, count, and detailed metadata.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class AttachmentInfo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the PDF contains any attachments
|
||||||
|
/// </summary>
|
||||||
|
public bool HasAttachments { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the total number of attachments in the PDF
|
||||||
|
/// </summary>
|
||||||
|
public int AttachmentCount { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the collection of attachment metadata (file details)
|
||||||
|
/// </summary>
|
||||||
|
public IReadOnlyList<AttachmentMetadata> Attachments { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the AttachmentInfo class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hasAttachments">Whether PDF has attachments</param>
|
||||||
|
/// <param name="attachmentCount">Total number of attachments</param>
|
||||||
|
/// <param name="attachments">List of attachment metadata (can be empty)</param>
|
||||||
|
public AttachmentInfo(bool hasAttachments, int attachmentCount, IReadOnlyList<AttachmentMetadata> attachments)
|
||||||
|
{
|
||||||
|
HasAttachments = hasAttachments;
|
||||||
|
AttachmentCount = attachmentCount;
|
||||||
|
Attachments = attachments ?? [];
|
||||||
|
|
||||||
|
// Defensive Programming: Ensure count matches list length
|
||||||
|
if (Attachments.Count != attachmentCount)
|
||||||
|
{
|
||||||
|
throw new ArgumentException(
|
||||||
|
$"Attachment count mismatch: expected {attachmentCount}, got {Attachments.Count}",
|
||||||
|
nameof(attachments));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates an AttachmentInfo instance for a PDF with no attachments.
|
||||||
|
/// </summary>
|
||||||
|
public static AttachmentInfo Empty =>
|
||||||
|
new(
|
||||||
|
hasAttachments: false,
|
||||||
|
attachmentCount: 0,
|
||||||
|
attachments: []);
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return HasAttachments
|
||||||
|
? $"PDF has {AttachmentCount} attachment(s): {string.Join(", ", Attachments.Select(a => a.FileName))}"
|
||||||
|
: "PDF has no attachments";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
namespace DocumentOperator.Application.Common.DTOs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents metadata of a single PDF attachment (embedded file).
|
||||||
|
/// Immutable value object containing file information without the actual binary data.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Initializes a new instance of the AttachmentMetadata class.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="fileName">Attachment file name</param>
|
||||||
|
/// <param name="mimeType">MIME type (e.g., "text/xml")</param>
|
||||||
|
/// <param name="sizeBytes">File size in bytes</param>
|
||||||
|
public sealed class AttachmentMetadata(string fileName, string mimeType, long sizeBytes)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the attachment file name (e.g., "invoice.xml", "document.pdf")
|
||||||
|
/// </summary>
|
||||||
|
public string FileName { get; } = fileName ?? string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the MIME type of the attachment (e.g., "text/xml", "application/pdf")
|
||||||
|
/// </summary>
|
||||||
|
public string MimeType { get; } = mimeType ?? "application/octet-stream"; // Default MIME type if unknown
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the attachment file size in bytes
|
||||||
|
/// </summary>
|
||||||
|
public long SizeBytes { get; } = sizeBytes;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the attachment file size in kilobytes (computed property)
|
||||||
|
/// </summary>
|
||||||
|
public double SizeKB => SizeBytes / 1024.0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the attachment file size in megabytes (computed property)
|
||||||
|
/// </summary>
|
||||||
|
public double SizeMB => SizeBytes / 1024.0 / 1024.0;
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"{FileName} ({MimeType}, {SizeKB:F2} KB)";
|
||||||
|
}
|
||||||
|
}
|
||||||
34
DocumentOperator.Application/Common/DTOs/PdfAMetadata.cs
Normal file
34
DocumentOperator.Application/Common/DTOs/PdfAMetadata.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
namespace DocumentOperator.Application.Common.DTOs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// PDF/A validation metadata including conformance level and validation errors/warnings
|
||||||
|
/// </summary>
|
||||||
|
public sealed class PdfAMetadata(
|
||||||
|
bool isValid,
|
||||||
|
string pdfVersion,
|
||||||
|
int pageCount,
|
||||||
|
long fileSizeBytes,
|
||||||
|
bool encrypted,
|
||||||
|
string? pdfaVersion,
|
||||||
|
bool pdfaCompliant,
|
||||||
|
IReadOnlyList<string> errors,
|
||||||
|
IReadOnlyList<string> warnings)
|
||||||
|
{
|
||||||
|
public bool IsValid { get; } = isValid;
|
||||||
|
public string PdfVersion { get; } = pdfVersion;
|
||||||
|
public int PageCount { get; } = pageCount;
|
||||||
|
public long FileSizeBytes { get; } = fileSizeBytes;
|
||||||
|
public bool Encrypted { get; } = encrypted;
|
||||||
|
public string? PdfAVersion { get; } = pdfaVersion;
|
||||||
|
public bool PdfACompliant { get; } = pdfaCompliant;
|
||||||
|
public IReadOnlyList<string> Errors { get; } = errors;
|
||||||
|
public IReadOnlyList<string> Warnings { get; } = warnings;
|
||||||
|
|
||||||
|
// Computed property
|
||||||
|
public double FileSizeMB => FileSizeBytes / 1024.0 / 1024.0;
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"PDF/A: {PdfAVersion ?? "None"}, {PageCount} pages, {FileSizeMB:F2} MB, Compliant: {PdfACompliant}";
|
||||||
|
}
|
||||||
|
}
|
||||||
23
DocumentOperator.Application/Common/DTOs/PdfMetadata.cs
Normal file
23
DocumentOperator.Application/Common/DTOs/PdfMetadata.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
namespace DocumentOperator.Application.Common.DTOs;
|
||||||
|
|
||||||
|
public sealed class PdfMetadata(
|
||||||
|
int pageCount,
|
||||||
|
long fileSizeBytes,
|
||||||
|
string pdfVersion,
|
||||||
|
bool hasAttachments,
|
||||||
|
int attachmentCount)
|
||||||
|
{
|
||||||
|
public int PageCount { get; } = pageCount;
|
||||||
|
public long FileSizeBytes { get; } = fileSizeBytes;
|
||||||
|
public string PdfVersion { get; } = pdfVersion;
|
||||||
|
public bool HasAttachments { get; } = hasAttachments;
|
||||||
|
public int AttachmentCount { get; } = attachmentCount;
|
||||||
|
|
||||||
|
// Computed Property (berechnet aus FileSizeBytes)
|
||||||
|
public double FileSizeMB => FileSizeBytes / 1024.0 / 1024.0;
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"PDF: {PageCount} pages, {FileSizeMB:F2} MB, Version {PdfVersion}, Attachments: {AttachmentCount}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
namespace DocumentOperator.Domain.Models.ValueObjects;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// PDF/A validation metadata including conformance level and validation errors/warnings
|
|
||||||
/// </summary>
|
|
||||||
public sealed class PdfAMetadata
|
|
||||||
{
|
|
||||||
public bool IsValid { get; }
|
|
||||||
public string PdfVersion { get; }
|
|
||||||
public int PageCount { get; }
|
|
||||||
public long FileSizeBytes { get; }
|
|
||||||
public bool Encrypted { get; }
|
|
||||||
public string? PdfAVersion { get; }
|
|
||||||
public bool PdfACompliant { get; }
|
|
||||||
public IReadOnlyList<string> Errors { get; }
|
|
||||||
public IReadOnlyList<string> Warnings { get; }
|
|
||||||
|
|
||||||
// Computed property
|
|
||||||
public double FileSizeMB => FileSizeBytes / 1024.0 / 1024.0;
|
|
||||||
|
|
||||||
public PdfAMetadata(
|
|
||||||
bool isValid,
|
|
||||||
string pdfVersion,
|
|
||||||
int pageCount,
|
|
||||||
long fileSizeBytes,
|
|
||||||
bool encrypted,
|
|
||||||
string? pdfaVersion,
|
|
||||||
bool pdfaCompliant,
|
|
||||||
IReadOnlyList<string> errors,
|
|
||||||
IReadOnlyList<string> warnings)
|
|
||||||
{
|
|
||||||
IsValid = isValid;
|
|
||||||
PdfVersion = pdfVersion;
|
|
||||||
PageCount = pageCount;
|
|
||||||
FileSizeBytes = fileSizeBytes;
|
|
||||||
Encrypted = encrypted;
|
|
||||||
PdfAVersion = pdfaVersion;
|
|
||||||
PdfACompliant = pdfaCompliant;
|
|
||||||
Errors = errors;
|
|
||||||
Warnings = warnings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return $"PDF/A: {PdfAVersion ?? "None"}, {PageCount} pages, {FileSizeMB:F2} MB, Compliant: {PdfACompliant}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
namespace DocumentOperator.Domain.Models.ValueObjects;
|
|
||||||
|
|
||||||
public sealed class PdfMetadata
|
|
||||||
{
|
|
||||||
public int PageCount { get; }
|
|
||||||
public long FileSizeBytes { get; }
|
|
||||||
public string PdfVersion { get; }
|
|
||||||
public bool HasAttachments { get; }
|
|
||||||
public int AttachmentCount { get; }
|
|
||||||
|
|
||||||
// Computed Property (berechnet aus FileSizeBytes)
|
|
||||||
public double FileSizeMB => FileSizeBytes / 1024.0 / 1024.0;
|
|
||||||
|
|
||||||
public PdfMetadata(
|
|
||||||
int pageCount,
|
|
||||||
long fileSizeBytes,
|
|
||||||
string pdfVersion,
|
|
||||||
bool hasAttachments,
|
|
||||||
int attachmentCount)
|
|
||||||
{
|
|
||||||
PageCount = pageCount;
|
|
||||||
FileSizeBytes = fileSizeBytes;
|
|
||||||
PdfVersion = pdfVersion;
|
|
||||||
HasAttachments = hasAttachments;
|
|
||||||
AttachmentCount = attachmentCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return $"PDF: {PageCount} pages, {FileSizeMB:F2} MB, Version {PdfVersion}, Attachments: {AttachmentCount}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user