Complete Phase 2: Domain Layer implementation

Updated ROADMAP.md to mark Phase 2 as completed and added detailed descriptions of completed tasks. Introduced three new value objects (`Base64String`, `TenantId`, and `PdfMetadata`) in the `DocumentOperator.Domain.Models.ValueObjects` namespace. These classes ensure type safety, immutability, and encapsulated validation.

- `Base64String`: Handles Base64 string creation, validation, and conversion.
- `TenantId`: Represents a tenant identifier with validation and normalization.
- `PdfMetadata`: Represents PDF metadata with computed properties.

Updated `DocumentOperator.Domain.csproj` to reflect the addition of these value objects. The project is now ready to begin Phase 3 (Infrastructure Layer).
This commit is contained in:
OlgunR
2026-06-18 14:32:06 +02:00
parent cdb942210c
commit 3a87ace144
5 changed files with 166 additions and 10 deletions

View File

@@ -9,7 +9,6 @@
<ItemGroup>
<Folder Include="Common\Results\" />
<Folder Include="Constants\" />
<Folder Include="Models\ValueObjects\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,59 @@
namespace DocumentOperator.Domain.Models.ValueObjects;
public sealed class Base64String
{
public string Value { get; }
private Base64String(string value)
{
Value = value;
}
public static Base64String Create(string value)
{
if (string.IsNullOrWhiteSpace(value))
throw new Common.Exceptions.DomainValidationException("Base64 string cannot be empty.");
// Validierung: Ist es gültiges Base64?
try
{
Convert.FromBase64String(value);
}
catch (FormatException)
{
throw new Common.Exceptions.DomainValidationException("Invalid Base64 format.");
}
return new Base64String(value);
}
public static Base64String FromByteArray(byte[] bytes)
{
if (bytes == null || bytes.Length == 0)
throw new Common.Exceptions.DomainValidationException("Byte array cannot be null or empty.");
var base64 = Convert.ToBase64String(bytes);
return new Base64String(base64);
}
public byte[] ToByteArray()
{
return Convert.FromBase64String(Value);
}
public override string ToString() => Value;
// Equality (wichtig für Value Objects!)
public override bool Equals(object? obj)
{
if (obj is not Base64String other)
return false;
return Value == other.Value;
}
public override int GetHashCode()
{
return Value.GetHashCode();
}
}

View File

@@ -0,0 +1,32 @@
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}";
}
}

View File

@@ -0,0 +1,41 @@
namespace DocumentOperator.Domain.Models.ValueObjects;
public sealed class TenantId
{
public string Value { get; }
private TenantId(string value)
{
Value = value;
}
public static TenantId Create(string value)
{
if (string.IsNullOrWhiteSpace(value))
throw new Common.Exceptions.DomainValidationException("TenantId cannot be empty.");
if (value.Length > 100)
throw new Common.Exceptions.DomainValidationException("TenantId cannot exceed 100 characters.");
// Normalisierung: Lowercase
var normalized = value.Trim().ToLowerInvariant();
return new TenantId(normalized);
}
public override string ToString() => Value;
// Equality
public override bool Equals(object? obj)
{
if (obj is not TenantId other)
return false;
return Value == other.Value;
}
public override int GetHashCode()
{
return Value.GetHashCode();
}
}