From 828bb168ebcc5f1d466d91677761527b4048f021 Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 23 Jul 2026 11:19:47 +0200 Subject: [PATCH] refactor(application): Remove old DTOs and mapping profiles, consolidate into EmailMappingProfile --- .../CreateEmailAttachmentDto.cs | 15 ----- .../EmailAttachments/EmailAttachmentDto.cs | 15 ----- .../UpdateEmailAttachmentStatusDto.cs | 10 ---- .../EmailHistories/CreateEmailHistoryDto.cs | 15 ----- .../Dtos/EmailHistories/EmailHistoryDto.cs | 21 ------- .../UpdateEmailHistoryStatusDto.cs | 11 ---- .../Common/Dtos/EmailProfileDto.cs | 18 ------ .../Mappings/EmailAccountMappingProfile.cs | 17 ------ .../Mappings/EmailAttachmentMappingProfile.cs | 51 ---------------- .../Mappings/EmailHistoryMappingProfile.cs | 59 ------------------- .../Common/Mappings/EmailMappingProfile.cs | 19 ++++++ .../Mappings/EmailOutboxMappingProfile.cs | 23 -------- .../Mappings/EmailProfileMappingProfile.cs | 20 ------- 13 files changed, 19 insertions(+), 275 deletions(-) delete mode 100644 src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailAttachments/CreateEmailAttachmentDto.cs delete mode 100644 src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailAttachments/EmailAttachmentDto.cs delete mode 100644 src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailAttachments/UpdateEmailAttachmentStatusDto.cs delete mode 100644 src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailHistories/CreateEmailHistoryDto.cs delete mode 100644 src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailHistories/EmailHistoryDto.cs delete mode 100644 src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailHistories/UpdateEmailHistoryStatusDto.cs delete mode 100644 src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailProfileDto.cs delete mode 100644 src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailAccountMappingProfile.cs delete mode 100644 src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailAttachmentMappingProfile.cs delete mode 100644 src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailHistoryMappingProfile.cs create mode 100644 src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailMappingProfile.cs delete mode 100644 src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailOutboxMappingProfile.cs delete mode 100644 src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailProfileMappingProfile.cs diff --git a/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailAttachments/CreateEmailAttachmentDto.cs b/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailAttachments/CreateEmailAttachmentDto.cs deleted file mode 100644 index e9dd250..0000000 --- a/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailAttachments/CreateEmailAttachmentDto.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace DigitalData.EmailProfiler.Application.Common.Dtos.EmailAttachments; - -/// -/// DTO for creating EmailAttachment record. -/// AutoMapper profile required: CreateEmailAttachmentDto -> EmailAttachment -/// -public record CreateEmailAttachmentDto( - int EmailHistoryId, - string OriginalFileName, - string SavedFileName, - string FilePath, - long FileSize, - string Extension, - string ContentType, - byte[] Content); diff --git a/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailAttachments/EmailAttachmentDto.cs b/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailAttachments/EmailAttachmentDto.cs deleted file mode 100644 index 5b37008..0000000 --- a/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailAttachments/EmailAttachmentDto.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace DigitalData.EmailProfiler.Application.Common.Dtos.EmailAttachments; - -/// -/// DTO for EmailAttachment query results. -/// -public class EmailAttachmentDto -{ - public int Id { get; set; } - public string OriginalFileName { get; set; } = string.Empty; - public string FilePath { get; set; } = string.Empty; - public long FileSize { get; set; } - public bool IsEmbeddedFile { get; set; } - public string? Status { get; set; } - public string? ValidationErrorMessage { get; set; } -} diff --git a/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailAttachments/UpdateEmailAttachmentStatusDto.cs b/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailAttachments/UpdateEmailAttachmentStatusDto.cs deleted file mode 100644 index b5302a0..0000000 --- a/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailAttachments/UpdateEmailAttachmentStatusDto.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace DigitalData.EmailProfiler.Application.Common.Dtos.EmailAttachments; - -/// -/// DTO for updating EmailAttachment status. -/// AutoMapper profile required: UpdateEmailAttachmentStatusDto -> EmailAttachment -/// -public record UpdateEmailAttachmentStatusDto( - string Status, - int? ValidationErrorCode = null, - string? ValidationErrorMessage = null); diff --git a/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailHistories/CreateEmailHistoryDto.cs b/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailHistories/CreateEmailHistoryDto.cs deleted file mode 100644 index b28beed..0000000 --- a/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailHistories/CreateEmailHistoryDto.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace DigitalData.EmailProfiler.Application.Common.Dtos.EmailHistories; - -/// -/// DTO for creating EmailHistory record. -/// AutoMapper profile required: CreateEmailHistoryDto -> EmailHistory -/// -public record CreateEmailHistoryDto( - int ProfileId, - string MessageIdHash, - string OriginalMessageId, - string SenderAddress, - DateTime EmailDate, - string Subject, - string? EmailBodyText, - string? EmailBodyHtml); diff --git a/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailHistories/EmailHistoryDto.cs b/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailHistories/EmailHistoryDto.cs deleted file mode 100644 index 838d410..0000000 --- a/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailHistories/EmailHistoryDto.cs +++ /dev/null @@ -1,21 +0,0 @@ -using DigitalData.EmailProfiler.Application.Common.Dtos.EmailAttachments; - -namespace DigitalData.EmailProfiler.Application.Common.Dtos.EmailHistories; - -/// -/// DTO for EmailHistory query results. -/// -public class EmailHistoryDto -{ - public int Id { get; set; } - public int? ProfileId { get; set; } - public string? ProfileName { get; set; } - public string? SenderAddress { get; set; } - public string? Subject { get; set; } - public DateTime? EmailDate { get; set; } - public DateTime? ProcessedDate { get; set; } - public string? Status { get; set; } - public int? ErrorCodeValue { get; set; } - public string? ErrorMessage { get; set; } - public List Attachments { get; set; } = new(); -} diff --git a/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailHistories/UpdateEmailHistoryStatusDto.cs b/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailHistories/UpdateEmailHistoryStatusDto.cs deleted file mode 100644 index 98dfb83..0000000 --- a/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailHistories/UpdateEmailHistoryStatusDto.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace DigitalData.EmailProfiler.Application.Common.Dtos.EmailHistories; - -/// -/// DTO for updating EmailHistory status. -/// AutoMapper profile required: UpdateEmailHistoryStatusDto -> EmailHistory -/// -public record UpdateEmailHistoryStatusDto( - string Status, - DateTime? ProcessedDate = null, - int? ErrorCodeValue = null, - string? ErrorMessage = null); diff --git a/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailProfileDto.cs b/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailProfileDto.cs deleted file mode 100644 index a8e765b..0000000 --- a/src/DigitalData.EmailProfiler.Application/Common/Dtos/EmailProfileDto.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace DigitalData.EmailProfiler.Application.Common.Dtos; - -/// -/// DTO for EmailProfile query results. -/// -public class EmailProfileDto -{ - public int Id { get; set; } - public string ProfileName { get; set; } = string.Empty; - public int EmailAccountId { get; set; } - public string? EmailAccountName { get; set; } - public int? ProcessId { get; set; } - public string? ProcessName { get; set; } - public int PollIntervalMinutes { get; set; } - public DateTime? LastPollTime { get; set; } - public bool IsActive { get; set; } - public string? Comment { get; set; } -} diff --git a/src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailAccountMappingProfile.cs b/src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailAccountMappingProfile.cs deleted file mode 100644 index 0873da3..0000000 --- a/src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailAccountMappingProfile.cs +++ /dev/null @@ -1,17 +0,0 @@ -using AutoMapper; -using DigitalData.EmailProfiler.Application.Common.Dtos; -using DigitalData.EmailProfiler.Domain.Entities; - -namespace DigitalData.EmailProfiler.Application.Common.Mappings; - -/// -/// AutoMapper profile for EmailAccount entity mappings. -/// -public class EmailAccountMappingProfile : Profile -{ - public EmailAccountMappingProfile() - { - // Entity -> DTO (for Queries) - CreateMap(); - } -} diff --git a/src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailAttachmentMappingProfile.cs b/src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailAttachmentMappingProfile.cs deleted file mode 100644 index 89c8428..0000000 --- a/src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailAttachmentMappingProfile.cs +++ /dev/null @@ -1,51 +0,0 @@ -using AutoMapper; -using DigitalData.EmailProfiler.Application.Common.Dtos.EmailAttachments; -using DigitalData.EmailProfiler.Domain.Entities; -using DigitalData.EmailProfiler.Domain.Enums; - -namespace DigitalData.EmailProfiler.Application.Common.Mappings; - -/// -/// AutoMapper profile for EmailAttachment entity mappings. -/// -public class EmailAttachmentMappingProfile : Profile -{ - public EmailAttachmentMappingProfile() - { - // DTO -> Entity (for Create) - CreateMap() - .ForMember(dest => dest.Id, opt => opt.Ignore()) // Auto-generated - .ForMember(dest => dest.Status, opt => opt.MapFrom(_ => AttachmentStatus.Pending.ToString())) - .ForMember(dest => dest.AddedWhen, opt => opt.MapFrom(_ => DateTime.Now)) - .ForMember(dest => dest.IsEmbeddedFile, opt => opt.MapFrom(_ => false)) - .ForMember(dest => dest.ParentAttachmentId, opt => opt.Ignore()) - .ForMember(dest => dest.AttachmentPosition, opt => opt.MapFrom(_ => 0)) - .ForMember(dest => dest.ValidationErrorCode, opt => opt.Ignore()) - .ForMember(dest => dest.ValidationErrorMessage, opt => opt.Ignore()) - .ForMember(dest => dest.Comment, opt => opt.Ignore()) - .ForMember(dest => dest.EmailHistory, opt => opt.Ignore()) - .ForMember(dest => dest.ParentAttachment, opt => opt.Ignore()) - .ForMember(dest => dest.EmbeddedFiles, opt => opt.Ignore()); - - // DTO -> Entity (for Update Status) - CreateMap() - .ForMember(dest => dest.Id, opt => opt.Ignore()) - .ForMember(dest => dest.EmailHistoryId, opt => opt.Ignore()) - .ForMember(dest => dest.OriginalFileName, opt => opt.Ignore()) - .ForMember(dest => dest.SavedFileName, opt => opt.Ignore()) - .ForMember(dest => dest.FilePath, opt => opt.Ignore()) - .ForMember(dest => dest.FileSize, opt => opt.Ignore()) - .ForMember(dest => dest.Extension, opt => opt.Ignore()) - .ForMember(dest => dest.IsEmbeddedFile, opt => opt.Ignore()) - .ForMember(dest => dest.ParentAttachmentId, opt => opt.Ignore()) - .ForMember(dest => dest.AttachmentPosition, opt => opt.Ignore()) - .ForMember(dest => dest.Comment, opt => opt.Ignore()) - .ForMember(dest => dest.AddedWhen, opt => opt.Ignore()) - .ForMember(dest => dest.EmailHistory, opt => opt.Ignore()) - .ForMember(dest => dest.ParentAttachment, opt => opt.Ignore()) - .ForMember(dest => dest.EmbeddedFiles, opt => opt.Ignore()); - - // Entity -> DTO (for Queries) - CreateMap(); - } -} diff --git a/src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailHistoryMappingProfile.cs b/src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailHistoryMappingProfile.cs deleted file mode 100644 index 6f37a8a..0000000 --- a/src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailHistoryMappingProfile.cs +++ /dev/null @@ -1,59 +0,0 @@ -using AutoMapper; -using DigitalData.EmailProfiler.Application.Common.Dtos.EmailHistories; -using DigitalData.EmailProfiler.Domain.Entities; -using DigitalData.EmailProfiler.Domain.Enums; - -namespace DigitalData.EmailProfiler.Application.Common.Mappings; - -/// -/// AutoMapper profile for EmailHistory entity mappings. -/// -public class EmailHistoryMappingProfile : Profile -{ - public EmailHistoryMappingProfile() - { - // DTO -> Entity (for Create) - CreateMap() - .ForMember(dest => dest.Id, opt => opt.Ignore()) // Auto-generated - .ForMember(dest => dest.EmailMessageId, opt => opt.Ignore()) // Auto-generated - .ForMember(dest => dest.Status, opt => opt.MapFrom(_ => EmailStatus.Processing.ToString())) - .ForMember(dest => dest.AddedWhen, opt => opt.MapFrom(_ => DateTime.Now)) - .ForMember(dest => dest.ProcessedDate, opt => opt.Ignore()) - .ForMember(dest => dest.ErrorCodeValue, opt => opt.Ignore()) - .ForMember(dest => dest.ErrorMessage, opt => opt.Ignore()) - .ForMember(dest => dest.WindreamDocumentId, opt => opt.Ignore()) - .ForMember(dest => dest.Comment, opt => opt.Ignore()) - .ForMember(dest => dest.WorkProcess, opt => opt.Ignore()) - .ForMember(dest => dest.ImapUid, opt => opt.Ignore()) - .ForMember(dest => dest.EmailSubstring1, opt => opt.Ignore()) - .ForMember(dest => dest.EmailSubstring2, opt => opt.Ignore()) - .ForMember(dest => dest.Profile, opt => opt.Ignore()) - .ForMember(dest => dest.Attachments, opt => opt.Ignore()); - - // DTO -> Entity (for Update Status) - CreateMap() - .ForMember(dest => dest.Id, opt => opt.Ignore()) - .ForMember(dest => dest.ProfileId, opt => opt.Ignore()) - .ForMember(dest => dest.MessageIdHash, opt => opt.Ignore()) - .ForMember(dest => dest.OriginalMessageId, opt => opt.Ignore()) - .ForMember(dest => dest.SenderAddress, opt => opt.Ignore()) - .ForMember(dest => dest.EmailDate, opt => opt.Ignore()) - .ForMember(dest => dest.Subject, opt => opt.Ignore()) - .ForMember(dest => dest.EmailBodyText, opt => opt.Ignore()) - .ForMember(dest => dest.EmailBodyHtml, opt => opt.Ignore()) - .ForMember(dest => dest.EmailMessageId, opt => opt.Ignore()) - .ForMember(dest => dest.AddedWhen, opt => opt.Ignore()) - .ForMember(dest => dest.WindreamDocumentId, opt => opt.Ignore()) - .ForMember(dest => dest.Comment, opt => opt.Ignore()) - .ForMember(dest => dest.WorkProcess, opt => opt.Ignore()) - .ForMember(dest => dest.ImapUid, opt => opt.Ignore()) - .ForMember(dest => dest.EmailSubstring1, opt => opt.Ignore()) - .ForMember(dest => dest.EmailSubstring2, opt => opt.Ignore()) - .ForMember(dest => dest.Profile, opt => opt.Ignore()) - .ForMember(dest => dest.Attachments, opt => opt.Ignore()); - - // Entity -> DTO (for Queries) - CreateMap() - .ForMember(dest => dest.ProfileName, opt => opt.MapFrom(src => src.Profile != null ? src.Profile.ProfileName : null)); - } -} diff --git a/src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailMappingProfile.cs b/src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailMappingProfile.cs new file mode 100644 index 0000000..37afb9f --- /dev/null +++ b/src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailMappingProfile.cs @@ -0,0 +1,19 @@ +using AutoMapper; +using DigitalData.EmailProfiler.Application.Common.Events; +using DigitalData.EmailProfiler.Application.EmailSending.Commands; + +namespace DigitalData.EmailProfiler.Application.Common.Mappings; + +/// +/// AutoMapper profile for Emails +/// +public class EmailMappingProfile : Profile +{ + public EmailMappingProfile() + { + // SendEmailCommand -> OutgoingEmailEvent + CreateMap() + .ForMember(dest => dest.Id, opt => opt.MapFrom(_ => Guid.NewGuid())) + .ForMember(dest => dest.QueuedAt, opt => opt.MapFrom(_ => DateTime.Now)); + } +} diff --git a/src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailOutboxMappingProfile.cs b/src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailOutboxMappingProfile.cs deleted file mode 100644 index 128d7bf..0000000 --- a/src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailOutboxMappingProfile.cs +++ /dev/null @@ -1,23 +0,0 @@ -using AutoMapper; -using DigitalData.EmailProfiler.Application.EmailSending.Commands; -using DigitalData.EmailProfiler.Domain.Entities; - -namespace DigitalData.EmailProfiler.Application.Common.Mappings; - -/// -/// AutoMapper profile for EmailOutbox entity -/// -public class EmailOutboxMappingProfile : Profile -{ - public EmailOutboxMappingProfile() - { - // SendEmailCommand -> EmailOutbox - CreateMap() - .ForMember(dest => dest.Id, opt => opt.Ignore()) // Auto-generated - .ForMember(dest => dest.Sent, opt => opt.Ignore()) // Set by handler - .ForMember(dest => dest.SentDate, opt => opt.Ignore()) // Set when sent - .ForMember(dest => dest.RetryCount, opt => opt.Ignore()) // Set by handler - .ForMember(dest => dest.AddedWhen, opt => opt.Ignore()) // Set by handler - .ForMember(dest => dest.EmailAccount, opt => opt.Ignore()); // Navigation property - } -} diff --git a/src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailProfileMappingProfile.cs b/src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailProfileMappingProfile.cs deleted file mode 100644 index b57bc2b..0000000 --- a/src/DigitalData.EmailProfiler.Application/Common/Mappings/EmailProfileMappingProfile.cs +++ /dev/null @@ -1,20 +0,0 @@ -using AutoMapper; -using DigitalData.EmailProfiler.Application.Common.Dtos; -using DigitalData.EmailProfiler.Domain.Entities; - -namespace DigitalData.EmailProfiler.Application.Common.Mappings; - -/// -/// AutoMapper profile for EmailProfile entity mappings. -/// -public class EmailProfileMappingProfile : Profile -{ - public EmailProfileMappingProfile() - { - // Entity -> DTO (for Queries) - CreateMap() - .ForMember(dest => dest.EmailAccountName, opt => opt.MapFrom(src => src.EmailAccount != null ? src.EmailAccount.AccountName : null)) - .ForMember(dest => dest.ProcessName, opt => opt.MapFrom(src => src.EmailProcess != null ? src.EmailProcess.ProcessName : null)) - .ForMember(dest => dest.LastPollTime, opt => opt.MapFrom(src => src.LastPollTime)); - } -}