feat(application): add MediatR commands and handlers with exception improvements

MediatR Commands (CQRS Pattern):
- CreateEmailProfileCommand + Handler
- UpdateEmailProfileCommand + Handler
- DeleteEmailProfileCommand + Handler
- CreateEmailAccountCommand + Handler
- ProcessEmailCommand + Handler (core email processing logic)

Command Handlers:
- Create/Update/Delete operations for EmailProfile
- Create operation for EmailAccount
- ProcessEmail: Complete email processing workflow including:
  * Duplicate detection using MessageId hash
  * Email history creation
  * PDF attachment validation
  * windream DMS archiving support (placeholder)
  * Domain event publishing (EmailProcessedEvent)
  * Error handling and status tracking

Exception Improvements:
- Added ErrorCode property to DomainException
- Added ErrorCode overload to ValidationException
- Simplified AttachmentProcessingException to use base ErrorCode

Field Mappings Fixed:
- EmailProfile: ProcessId (not EmailProcessId), ValidationSql (not SenderFilter/SubjectFilter)
- EmailAccount: Username, EncryptedPassword, UseOAuth2, EncryptedClientSecret
- EmailHistory: SenderAddress, EmailDate, OriginalMessageId, EmailBodyText/Html
- EmailAttachment: OriginalFileName, SavedFileName, FilePath, FileSize
- Audit fields: AddedWhen/AddedWho, ChangedWhen/ChangedWho (not CreatedDate/By, ModifiedDate/By)

All commands follow Clean Architecture and use UnitOfWork pattern.
Build successful with 1 minor warning (dmsService marked for future implementation).
This commit is contained in:
2026-07-08 15:51:51 +02:00
parent 3778c0b338
commit 45654796b7
13 changed files with 348 additions and 6 deletions

View File

@@ -1,3 +1,5 @@
using DigitalData.EmailProfiler.Domain.Enums;
namespace DigitalData.EmailProfiler.Domain.Exceptions;
public class ValidationException : DomainException
@@ -6,6 +8,10 @@ public class ValidationException : DomainException
{
}
public ValidationException(string message, ErrorCode errorCode) : base(message, errorCode)
{
}
public ValidationException(string message, Exception innerException) : base(message, innerException)
{
}