Referenztyp hinzugefügt, um zu klassifizieren, für wen Geschichte geschrieben wird.

This commit is contained in:
Developer 02 2024-06-04 13:50:17 +02:00
parent 65618e5df9
commit 34b3c46720
10 changed files with 66 additions and 15 deletions

View File

@ -15,7 +15,7 @@ namespace EnvelopeGenerator.Application.Contracts
Task<bool> IsSigned(int envelopeId, string userReference); Task<bool> IsSigned(int envelopeId, string userReference);
Task<IEnumerable<EnvelopeHistoryDto>> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null); Task<IEnumerable<EnvelopeHistoryDto>> ReadAsync(int? envelopeId = null, string? userReference = null, ReferenceType? referenceType = null, int? status = null);
Task<IEnumerable<EnvelopeHistoryDto>> ReadRejectedAsync(int envelopeId, string? userReference = null); Task<IEnumerable<EnvelopeHistoryDto>> ReadRejectedAsync(int envelopeId, string? userReference = null);

View File

@ -0,0 +1,14 @@
using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Application.Services;
using Microsoft.Extensions.DependencyInjection;
using static EnvelopeGenerator.Common.Constants;
namespace EnvelopeGenerator.Application
{
public static class DIExtensions
{
public static IServiceCollection AddHistoryService(this IServiceCollection services, Func<EnvelopeStatus, ReferenceType>? classifier = null) => services
.AddSingleton(classifier ?? EnvelopeHistoryService.DefaultClassifier)
.AddScoped<IEnvelopeHistoryService, EnvelopeHistoryService>();
}
}

View File

@ -1,4 +1,7 @@
namespace EnvelopeGenerator.Application.DTOs.EnvelopeHistory using DigitalData.UserManager.Application.DTOs.User;
using static EnvelopeGenerator.Common.Constants;
namespace EnvelopeGenerator.Application.DTOs.EnvelopeHistory
{ {
public record EnvelopeHistoryDto( public record EnvelopeHistoryDto(
long Id, long Id,
@ -7,6 +10,8 @@
int Status, int Status,
DateTime AddedWhen, DateTime AddedWhen,
DateTime? ActionDate, DateTime? ActionDate,
UserCreateDto? Sender,
ReceiverDto? Receiver, ReceiverDto? Receiver,
ReferenceType ReferenceType,
string? Comment = null); string? Comment = null);
} }

View File

@ -50,11 +50,15 @@ namespace EnvelopeGenerator.Application.Services
status: (int)EnvelopeStatus.DocumentRejected) > 0; status: (int)EnvelopeStatus.DocumentRejected) > 0;
} }
public async Task<IEnumerable<EnvelopeHistoryDto>> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null) => _mapper.MapOrThrow<IEnumerable<EnvelopeHistoryDto>>( public async Task<IEnumerable<EnvelopeHistoryDto>> ReadAsync(int? envelopeId = null, string? userReference = null, ReferenceType? referenceType = null, int? status = null)
{
var histDTOs = _mapper.MapOrThrow<IEnumerable<EnvelopeHistoryDto>>(
await _repository.ReadAsync( await _repository.ReadAsync(
envelopeId: envelopeId, envelopeId: envelopeId,
userReference: userReference, userReference: userReference,
status: status)); status: status));
return referenceType is null ? histDTOs : histDTOs.Where(h => h.ReferenceType == referenceType);
}
public async Task<IEnumerable<EnvelopeHistoryDto>> ReadRejectedAsync(int envelopeId, string? userReference = null) => public async Task<IEnumerable<EnvelopeHistoryDto>> ReadRejectedAsync(int envelopeId, string? userReference = null) =>
await ReadAsync(envelopeId: envelopeId, userReference: userReference, status: (int)EnvelopeStatus.DocumentRejected); await ReadAsync(envelopeId: envelopeId, userReference: userReference, status: (int)EnvelopeStatus.DocumentRejected);

View File

@ -26,6 +26,13 @@
MessageCompletionSent = 3005 MessageCompletionSent = 3005
End Enum End Enum
Public Enum ReferenceType
Receiver
Sender
System
Unknown
End Enum
Public Enum ElementStatus Public Enum ElementStatus
Created = 0 Created = 0
End Enum End Enum

View File

@ -1,5 +1,7 @@
using System.ComponentModel.DataAnnotations; using DigitalData.UserManager.Domain.Entities;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using static EnvelopeGenerator.Common.Constants;
namespace EnvelopeGenerator.Domain.Entities namespace EnvelopeGenerator.Domain.Entities
{ {
@ -34,10 +36,18 @@ namespace EnvelopeGenerator.Domain.Entities
[Column("COMMENT", TypeName = "nvarchar(max)")] [Column("COMMENT", TypeName = "nvarchar(max)")]
public string? Comment { get; set; } public string? Comment { get; set; }
//[ForeignKey("UserReference")] [ForeignKey("UserReference")]
//public virtual DigitalData.UserManager.Domain.Entities.User? Sender { get; set; } public virtual User? Sender { get; set; }
[ForeignKey("UserReference")] [ForeignKey("UserReference")]
public virtual Receiver? Receiver { get; set; } public virtual Receiver? Receiver { get; set; }
[NotMapped]
public ReferenceType ReferenceType => (Status / 3) switch
{
1 => ReferenceType.Sender,
2 or 3 => ReferenceType.Receiver,
_ => ReferenceType.Unknown,
};
} }
} }

View File

@ -7,6 +7,6 @@ namespace EnvelopeGenerator.Infrastructure.Contracts
{ {
Task<int> CountAsync(int? envelopeId = null, string? userReference = null, int? status = null); Task<int> CountAsync(int? envelopeId = null, string? userReference = null, int? status = null);
Task<IEnumerable<EnvelopeHistory>> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null, bool withReceiver = true); Task<IEnumerable<EnvelopeHistory>> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null, bool withSender = false, bool withReceiver = false);
} }
} }

View File

@ -54,6 +54,12 @@ namespace DigitalData.UserManager.Infrastructure.Repositories
.HasForeignKey(eh => eh.UserReference) .HasForeignKey(eh => eh.UserReference)
.HasPrincipalKey(e => e.EmailAddress); .HasPrincipalKey(e => e.EmailAddress);
modelBuilder.Entity<EnvelopeHistory>()
.HasOne(eh => eh.Sender)
.WithMany()
.HasForeignKey(eh => eh.UserReference)
.HasPrincipalKey(e => e.Email);
// Configure entities to handle database triggers // Configure entities to handle database triggers
modelBuilder.Entity<Envelope>().ToTable(tb => tb.HasTrigger("TBSIG_ENVELOPE_HISTORY_AFT_INS")); modelBuilder.Entity<Envelope>().ToTable(tb => tb.HasTrigger("TBSIG_ENVELOPE_HISTORY_AFT_INS"));
modelBuilder.Entity<EnvelopeHistory>().ToTable(tb => tb.HasTrigger("TBSIG_ENVELOPE_HISTORY_AFT_INS")); modelBuilder.Entity<EnvelopeHistory>().ToTable(tb => tb.HasTrigger("TBSIG_ENVELOPE_HISTORY_AFT_INS"));

View File

@ -12,7 +12,7 @@ namespace EnvelopeGenerator.Infrastructure.Repositories
{ {
} }
private IQueryable<EnvelopeHistory> By(int? envelopeId = null, string? userReference = null, int? status = null, bool withReceiver = false) private IQueryable<EnvelopeHistory> By(int? envelopeId = null, string? userReference = null, int? status = null, bool withSender = false, bool withReceiver = false)
{ {
var query = _dbSet.AsQueryable(); var query = _dbSet.AsQueryable();
@ -25,6 +25,9 @@ namespace EnvelopeGenerator.Infrastructure.Repositories
if (status is not null) if (status is not null)
query = query.Where(eh => eh.Status == status); query = query.Where(eh => eh.Status == status);
if (withSender)
query = query.Include(eh => eh.Sender);
if (withReceiver) if (withReceiver)
query = query.Include(eh => eh.Receiver); query = query.Include(eh => eh.Receiver);
@ -36,10 +39,12 @@ namespace EnvelopeGenerator.Infrastructure.Repositories
userReference: userReference, userReference: userReference,
status: status).CountAsync(); status: status).CountAsync();
public async Task<IEnumerable<EnvelopeHistory>> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null, bool withReceiver = true) => await By( public async Task<IEnumerable<EnvelopeHistory>> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null, bool withSender = false, bool withReceiver = false)
=> await By(
envelopeId: envelopeId, envelopeId: envelopeId,
userReference: userReference, userReference: userReference,
status: status, status: status,
withSender: withSender,
withReceiver: withReceiver).ToListAsync(); withReceiver: withReceiver).ToListAsync();
} }
} }

View File

@ -100,11 +100,11 @@ try
builder.Services.AddScoped<IEnvelopeService, EnvelopeService>(); builder.Services.AddScoped<IEnvelopeService, EnvelopeService>();
builder.Services.AddScoped<IEnvelopeCertificateService, EnvelopeCertificateService>(); builder.Services.AddScoped<IEnvelopeCertificateService, EnvelopeCertificateService>();
builder.Services.AddScoped<IEnvelopeDocumentService, EnvelopeDocumentService>(); builder.Services.AddScoped<IEnvelopeDocumentService, EnvelopeDocumentService>();
builder.Services.AddScoped<IEnvelopeHistoryService, EnvelopeHistoryService>();
builder.Services.AddScoped<IEnvelopeReceiverService, EnvelopeReceiverService>(); builder.Services.AddScoped<IEnvelopeReceiverService, EnvelopeReceiverService>();
builder.Services.AddScoped<IEnvelopeTypeService, EnvelopeTypeService>(); builder.Services.AddScoped<IEnvelopeTypeService, EnvelopeTypeService>();
builder.Services.AddScoped<IReceiverService, ReceiverService>(); builder.Services.AddScoped<IReceiverService, ReceiverService>();
builder.Services.AddScoped<IUserReceiverService, UserReceiverService>(); builder.Services.AddScoped<IUserReceiverService, UserReceiverService>();
builder.Services.AddHistoryService();
//Auto mapping profiles //Auto mapping profiles
builder.Services.AddAutoMapper(typeof(BasicDtoMappingProfile).Assembly); builder.Services.AddAutoMapper(typeof(BasicDtoMappingProfile).Assembly);