Refactor ReportItem creation and encapsulate mapping

Moved mapping logic from ReportCreator.ToReportItem to a new constructor in ReportItem, improving encapsulation and simplifying report generation. Updated usings to remove unused and add necessary dependencies.
This commit is contained in:
2026-04-01 11:15:33 +02:00
parent 052da02bd0
commit 3855a8fa1e
2 changed files with 18 additions and 19 deletions

View File

@@ -1,6 +1,5 @@
using DevExpress.Xpo;
using DigitalData.Core.Abstraction.Application.Repository;
using EnvelopeGenerator.Domain.Constants;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.ServiceHost.Exceptions;
@@ -16,7 +15,7 @@ public class ReportCreator(IRepository<EnvelopeReport> reportRepo)
throw new CreateReportException("Could not prepare report data! No report data found!");
var items = reports
.Select(r => ToReportItem(r, envelope))
.Select(r => new ReportItem(r, envelope))
.OrderByDescending(r => r.ItemDate)
.ToList();
@@ -27,21 +26,4 @@ public class ReportCreator(IRepository<EnvelopeReport> reportRepo)
report.ExportToPdf(stream);
return stream.ToArray();
}
private static ReportItem ToReportItem(EnvelopeReport report, Envelope envelope)
{
return new ReportItem
{
CreatorFullName = envelope.User is not null
? $"{envelope.User.Prename} {envelope.User.Name}".Trim()
: string.Empty,
CreatorEmailAddress = envelope.User?.Email ?? string.Empty,
EnvelopeTitle = report.HeadTitle ?? string.Empty,
EnvelopeUuid = report.HeadUuid ?? string.Empty,
EnvelopeCertificationType = envelope.CertificationType is int certType ? ((CertificationType)certType).ToString() : "null",
ItemStatus = (EnvelopeStatus)report.PosStatus,
ItemUserReference = report.PosWho ?? string.Empty,
ItemDate = report.PosWhen ?? DateTime.MinValue
};
}
}

View File

@@ -1,9 +1,26 @@
using EnvelopeGenerator.Domain.Constants;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument;
public class ReportItem
{
public ReportItem() { }
public ReportItem(EnvelopeReport report, Envelope envelope)
{
CreatorFullName = envelope.User is not null
? $"{envelope.User.Prename} {envelope.User.Name}".Trim()
: string.Empty;
CreatorEmailAddress = envelope.User?.Email ?? string.Empty;
EnvelopeTitle = report.HeadTitle ?? string.Empty;
EnvelopeUuid = report.HeadUuid ?? string.Empty;
EnvelopeCertificationType = envelope.CertificationType is int certType ? ((CertificationType)certType).ToString() : "null";
ItemStatus = (EnvelopeStatus)report.PosStatus;
ItemUserReference = report.PosWho ?? string.Empty;
ItemDate = report.PosWhen ?? DateTime.MinValue;
}
// Header fields (from Envelope)
public string CreatorFullName { get; set; } = string.Empty;
public string CreatorEmailAddress { get; set; } = string.Empty;