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<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);

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(
long Id,
@ -7,6 +10,8 @@
int Status,
DateTime AddedWhen,
DateTime? ActionDate,
UserCreateDto? Sender,
ReceiverDto? Receiver,
ReferenceType ReferenceType,
string? Comment = null);
}

View File

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

View File

@ -26,6 +26,13 @@
MessageCompletionSent = 3005
End Enum
Public Enum ReferenceType
Receiver
Sender
System
Unknown
End Enum
Public Enum ElementStatus
Created = 0
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 static EnvelopeGenerator.Common.Constants;
namespace EnvelopeGenerator.Domain.Entities
{
@ -34,10 +36,18 @@ namespace EnvelopeGenerator.Domain.Entities
[Column("COMMENT", TypeName = "nvarchar(max)")]
public string? Comment { get; set; }
//[ForeignKey("UserReference")]
//public virtual DigitalData.UserManager.Domain.Entities.User? Sender { get; set; }
[ForeignKey("UserReference")]
public virtual User? Sender { get; set; }
[ForeignKey("UserReference")]
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<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)
.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
modelBuilder.Entity<Envelope>().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();
@ -25,7 +25,10 @@ namespace EnvelopeGenerator.Infrastructure.Repositories
if (status is not null)
query = query.Where(eh => eh.Status == status);
if(withReceiver)
if (withSender)
query = query.Include(eh => eh.Sender);
if (withReceiver)
query = query.Include(eh => eh.Receiver);
return query;
@ -36,10 +39,12 @@ namespace EnvelopeGenerator.Infrastructure.Repositories
userReference: userReference,
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,
userReference: userReference,
status: status,
withSender: withSender,
withReceiver: withReceiver).ToListAsync();
}
}

View File

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