Compare commits

...

16 Commits

Author SHA1 Message Date
f34770931f feat(CreateHistoryCommand): add CreateHistoryCommandHandler with repository integration
- Extend CreateHistoryCommand to implement IRequest<long?>
- Introduce CreateHistoryCommandHandler to handle command via IRepository<EnvelopeHistory>
- Implement async creation and verification of EnvelopeHistory records
2025-08-25 17:33:49 +02:00
78100ef24f create CreateHistoryCommand 2025-08-25 17:22:26 +02:00
99083a68aa move mapping profile to pre dir 2025-08-25 16:50:42 +02:00
0939e57c56 refactor(EnvelopeController): migrate envelope update to MediatR with annotations
- Renamed `Update` action to `CreateOrUpdate`.
- Replaced manual signing logic with `_mediator.SignDocAsync`.
- Added `ExpandoObject` parameter to handle document annotations.
- Improved authorization checks and logging for missing claims.
- Kept legacy `Reject` endpoint intact with obsolete services.
2025-08-25 16:40:46 +02:00
00bdfeb9bb refactor(query): restructure ReceiverAlreadySignedQuery for clarity
- Replaced internal string properties with EnvelopeQuery and ReceiverQuery records
- Updated Key property to encode/decode using the new structured types
- Added overloaded IMediator extension methods IsSignedAsync for better usability
- Simplified ReceiverAlreadySignedQueryHandler to work with the new structure
2025-08-25 16:27:37 +02:00
cced0e5579 refator(SaveDocStatusCommandHandler): use SingleOrDefaultAsync instead of FirstOrDefaultAsync 2025-08-25 15:56:37 +02:00
82150290d2 refactor(Extensions): update SaveDocStatusAsync to use uuid and signature 2025-08-25 15:55:37 +02:00
fb7fd47a2a feat(SaveDocStatusCommand): add IMediator extension methods for saving and signing document status
- Introduced `SaveDocStatusAsync` extension method on IMediator to simplify saving document status
- Added `SignDocAsync` extension method as a shortcut for signing document status
- Refactored `SaveDocStatusCommand` usage to support new mediator extension
2025-08-25 15:43:54 +02:00
20b6b328f5 feat(EGDbContext): Eindeutige Indizes und Beziehungen für die Entitäten „Envelope“, „Receiver“ und „DocumentStatus“ hinzufügen
- Eindeutiger Index für „Envelope.Uuid“ hinzugefügt
- Eindeutige Indizes für „Receiver.Signature“ und „Receiver.EmailAddress“ hinzugefügt
- Beziehungen von „DocumentStatus“ zu „Envelope.Uuid“ und „Receiver“ (Signature und EmailAddress) konfiguriert
- Entitätsbeschränkungen für die Datenintegrität verbessert
2025-08-25 15:32:48 +02:00
fb07d9151f add mapping profiles 2025-08-25 15:20:29 +02:00
a3bc26bd08 feat(SaveDocStatusCommand): enhance SaveDocStatusCommandHandler with flexible envelope & receiver filters
- Added support for filtering by Envelope.Id or Envelope.Uuid
- Added support for filtering by Receiver.Id, Receiver.EmailAddress, or Receiver.Signature
- Throw BadRequestException when required identifiers are missing
- Updated repository queries to combine envelope and receiver filters
2025-08-25 15:02:57 +02:00
e1f793e571 refactor(TaskExtensions): TaskExtensions verallgemeinern, um benutzerdefinierte Ausnahmegeneratoren zu unterstützen
- Feste NotFoundException durch generischen Ausnahmegenerator in ThrowIfNull-Methoden ersetzt.
- Neue Exceptions-Hilfsklasse für die Erstellung gängiger Ausnahmen (NotFound, BadRequest, Forbidden) hinzugefügt.
- Funktionalität der Then-Erweiterungsmethode unverändert beibehalten.
2025-08-25 12:41:27 +02:00
86d8fcda07 chore: update to use DigitalData.Core.Exceptions instead of project exceptions classes 2025-08-25 11:48:29 +02:00
2f8401073f feat(SaveDocStatusCommand): Füge SaveDocStatusCommand und Handler hinzu, um den Dokumentstatus zu erstellen oder zu aktualisieren. 2025-08-25 11:41:08 +02:00
85a855fe64 refactor(ModifyDocStatusCommandBase): remove ChangedWhen-property 2025-08-25 11:18:48 +02:00
996b544633 feat(ModifyDocStatusCommandBase): create abstract class to handle common properties of commands 2025-08-25 11:16:57 +02:00
29 changed files with 493 additions and 144 deletions

View File

@@ -1,19 +1,12 @@
using EnvelopeGenerator.Domain;
namespace EnvelopeGenerator.Application.DocStatus.Commands;
namespace EnvelopeGenerator.Application.DocStatus.Commands;
/// <summary>
///
/// </summary>
public class CreateDocStatusCommand : UpdateDocStatusCommand
public record CreateDocStatusCommand : ModifyDocStatusCommandBase
{
/// <summary>
/// Gets timestamp when this record was added. Returns the current date and time.
/// Gets timestamp when this record was added. Returns the StatusChangedWhen value.
/// </summary>
public DateTime AddedWhen => StatusChangedWhen;
/// <summary>
/// Gets timestamp when this record was added. Returns the current date and time.
/// </summary>
public override DateTime? ChangedWhen { get; } = null;
}

View File

@@ -0,0 +1,113 @@
using DigitalData.Core.Exceptions;
using EnvelopeGenerator.Domain;
using EnvelopeGenerator.Extensions;
namespace EnvelopeGenerator.Application.DocStatus.Commands;
/// <summary>
///
/// </summary>
public record ModifyDocStatusCommandBase
{
/// <summary>
///
/// </summary>
public string? Key
{
get => Envelope?.Uuid is string uuid && Receiver?.Signature is string signature
? (uuid, signature).EncodeEnvelopeReceiverId()
: null;
init
{
if (value is null)
return;
(string? EnvelopeUuid, string? ReceiverSignature) = value.DecodeEnvelopeReceiverId();
if (string.IsNullOrEmpty(EnvelopeUuid) || string.IsNullOrEmpty(ReceiverSignature))
{
throw new BadRequestException("Der EnvelopeReceiverKey muss ein gültiger Base64-kodierter String sein, der die EnvelopeUuid und die ReceiverSignature enthält.");
}
Envelope.Uuid = EnvelopeUuid;
Receiver.Signature = ReceiverSignature;
}
}
/// <summary>
/// Der Umschlag, der mit dem Empfänger verknüpft ist.
/// </summary>
public EnvelopeQuery Envelope { get; set; } = new();
/// <summary>
/// Der Empfänger, der mit dem Umschlag verknüpft ist.
/// </summary>
public ReceiverQuery Receiver { get; set; } = new();
/// <summary>
/// Gets the current status code.
/// </summary>
public Constants.DocumentStatus Status => Value is null ? Constants.DocumentStatus.Created : Constants.DocumentStatus.Signed;
/// <summary>
/// Gets or sets the display value associated with the status.
/// </summary>
public string? Value { get; set; }
/// <summary>
/// Gets timestamp when this record was added.
/// </summary>
public DateTime StatusChangedWhen { get; } = DateTime.Now;
/// <summary>
/// Maps the current command to a new instance of the specified type.
/// </summary>
/// <typeparam name="TDest"></typeparam>
/// <returns></returns>
public TDest To<TDest>() where TDest : ModifyDocStatusCommandBase, new()
=> new()
{
Key = Key,
Envelope = Envelope,
Receiver = Receiver,
Value = Value
};
}
#region Queries
/// <summary>
/// Repräsentiert eine Abfrage für Umschläge.
/// </summary>
public record EnvelopeQuery
{
/// <summary>
/// Die eindeutige Kennung des Umschlags.
/// </summary>
public int? Id { get; init; }
/// <summary>
/// Die universell eindeutige Kennung des Umschlags.
/// </summary>
public string? Uuid { get; set; }
}
/// <summary>
/// Stellt eine Abfrage dar, um die Details eines Empfängers zu lesen.
/// um spezifische Informationen über einen Empfänger abzurufen.
/// </summary>
public record ReceiverQuery
{
/// <summary>
/// ID des Empfängers
/// </summary>
public int? Id { get; init; }
/// <summary>
/// E-Mail Adresse des Empfängers
/// </summary>
public string? EmailAddress { get; init; }
/// <summary>
/// Eindeutige Signatur des Empfängers
/// </summary>
public string? Signature { get; set; }
}
#endregion

View File

@@ -0,0 +1,97 @@
using DigitalData.Core.Abstraction.Application.Repository;
using DigitalData.Core.Exceptions;
using EnvelopeGenerator.Domain.Entities;
using MediatR;
using Microsoft.EntityFrameworkCore;
using System.Linq.Expressions;
namespace EnvelopeGenerator.Application.DocStatus.Commands;
/// <summary>
/// Represents a command to save the status of a document, either by creating a new status or updating an existing one based on the provided envelope and receiver identifiers.
/// It returns the identifier of the saved document status.
/// </summary>
public record SaveDocStatusCommand : ModifyDocStatusCommandBase, IRequest<int?>;
/// <summary>
///
/// </summary>
public static class Extensions
{
/// <summary>
///
/// </summary>
/// <param name="mediator"></param>
/// <param name="uuid"></param>
/// <param name="signature"></param>
/// <param name="value"></param>
/// <param name="cancel"></param>
/// <returns></returns>
public static Task<int?> SignDocAsync(this IMediator mediator, string uuid, string signature, string value, CancellationToken cancel = default)
=> mediator.Send(new SaveDocStatusCommand()
{
Envelope = new() { Uuid = uuid },
Receiver = new() { Signature = signature },
Value = value
}, cancel);
}
/// <summary>
///
/// </summary>
public class SaveDocStatusCommandHandler : IRequestHandler<SaveDocStatusCommand, int?>
{
private readonly IRepository<DocumentStatus> _repo;
/// <summary>
///
/// </summary>
/// <param name="repo"></param>
public SaveDocStatusCommandHandler(IRepository<DocumentStatus> repo)
{
_repo = repo;
}
/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <param name="cancel"></param>
/// <returns></returns>
public async Task<int?> Handle(SaveDocStatusCommand request, CancellationToken cancel)
{
// envelope filter
Expression<Func<DocumentStatus, bool>>? eExp =
request.Envelope.Id is not null
? ds => ds.EnvelopeId == request.Envelope.Id
: !string.IsNullOrWhiteSpace(request.Envelope.Uuid)
? ds => ds.Envelope.Uuid == request.Envelope.Uuid
: throw new BadRequestException();
// receiver filter
Expression<Func<DocumentStatus, bool>>? rExp =
request.Receiver.Id is not null
? ds => ds.ReceiverId == request.Receiver.Id
: request.Receiver.EmailAddress is not null
? ds => ds.Receiver.EmailAddress == request.Receiver.EmailAddress
: !string.IsNullOrWhiteSpace(request.Receiver.Signature) ? ds => ds.Receiver.Signature == request.Receiver.Signature
: throw new BadRequestException();
// ceck if exists
bool isExists = await _repo.ReadOnly().Where(eExp).Where(rExp).AnyAsync(cancel);
if (isExists)
{
var uReq = request.To<UpdateDocStatusCommand>();
await _repo.UpdateAsync(uReq, q => q.Where(eExp).Where(rExp), cancel);
}
else
{
var cReq = request.To<CreateDocStatusCommand>();
await _repo.CreateAsync(cReq, cancel);
}
var docStatus = await _repo.ReadOnly().Where(eExp).Where(rExp).SingleOrDefaultAsync(cancel);
return docStatus?.Id;
}
}

View File

@@ -5,35 +5,10 @@ namespace EnvelopeGenerator.Application.DocStatus.Commands;
/// <summary>
///
/// </summary>
public class UpdateDocStatusCommand
public record UpdateDocStatusCommand : ModifyDocStatusCommandBase
{
/// <summary>
/// Gets or sets the ID of the associated envelope.
/// Gets timestamp when this record was added. Returns the StatusChangedWhen value.
/// </summary>
public int EnvelopeId { get; set; }
/// <summary>
/// Gets or sets the ID of the receiver associated with this status.
/// </summary>
public int ReceiverId { get; set; }
/// <summary>
/// Gets the current status code.
/// </summary>
public Constants.DocumentStatus Status => Value is null ? Constants.DocumentStatus.Created : Constants.DocumentStatus.Signed;
/// <summary>
/// Gets the timestamp when the status was changed. Retrns the AddedWhen value.
/// </summary>
public DateTime StatusChangedWhen { get; } = DateTime.Now;
/// <summary>
/// Gets or sets the display value associated with the status.
/// </summary>
public string? Value { get; set; }
/// <summary>
/// Gets timestamp when this record was added. Returns the current date and time.
/// </summary>
public virtual DateTime? ChangedWhen { get; } = DateTime.Now;
public DateTime? ChangedWhen => StatusChangedWhen;
}

View File

@@ -0,0 +1,22 @@
using AutoMapper;
using EnvelopeGenerator.Application.DocStatus.Commands;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.DocStatus;
/// <summary>
///
/// </summary>
public class MappingProfile : Profile
{
/// <summary>
///
/// </summary>
public MappingProfile()
{
CreateMap<CreateDocStatusCommand, DocumentStatus>();
CreateMap<UpdateDocStatusCommand, DocumentStatus>();
CreateMap<EnvelopeQuery, Envelope>();
CreateMap<ReceiverQuery, Receiver>();
}
}

View File

@@ -1,7 +1,7 @@
using AutoMapper;
using DigitalData.Core.Abstraction.Application.Repository;
using EnvelopeGenerator.Application.Dto;
using EnvelopeGenerator.Application.Exceptions;
using DigitalData.Core.Exceptions;
using EnvelopeGenerator.Domain;
using EnvelopeGenerator.Domain.Entities;
using MediatR;

View File

@@ -14,9 +14,10 @@
<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.66" />
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.1.0" />
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.2.1" />
<PackageReference Include="DigitalData.Core.Application" Version="3.4.0" />
<PackageReference Include="DigitalData.Core.Client" Version="2.1.0" />
<PackageReference Include="DigitalData.Core.Exceptions" Version="1.1.0" />
<PackageReference Include="DigitalData.EmailProfilerDispatcher" Version="3.1.1" />
<PackageReference Include="MediatR" Version="12.5.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.18" />

View File

@@ -1,6 +1,6 @@
using EnvelopeGenerator.Application.Dto.EnvelopeReceiver;
using EnvelopeGenerator.Application.Envelopes.Queries;
using EnvelopeGenerator.Application.Exceptions;
using DigitalData.Core.Exceptions;
using EnvelopeGenerator.Application.Extensions;
using EnvelopeGenerator.Application.Receivers.Queries;
using EnvelopeGenerator.Extensions;

View File

@@ -1,5 +1,5 @@
using DigitalData.Core.Abstraction.Application.Repository;
using EnvelopeGenerator.Application.Exceptions;
using DigitalData.Core.Exceptions;
using EnvelopeGenerator.Domain;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Extensions;
@@ -16,9 +16,9 @@ public record ReceiverAlreadySignedQuery : IRequest<bool>
/// <summary>
///
/// </summary>
public required string Key
public string Key
{
get => (EnvelopeUuid, ReceiverSignature).EncodeEnvelopeReceiverId();
get => (Envelope.Uuid, Receiver.Signature).EncodeEnvelopeReceiverId();
init
{
(string? EnvelopeUuid, string? ReceiverSignature) = value.DecodeEnvelopeReceiverId();
@@ -29,11 +29,41 @@ public record ReceiverAlreadySignedQuery : IRequest<bool>
}
}
internal string EnvelopeUuid { get; set; } = null!;
/// <summary>
///
/// </summary>
public EnvelopeQuery Envelope { get; set; } = new EnvelopeQuery();
internal string ReceiverSignature { get; set; } = null!;
/// <summary>
///
/// </summary>
public ReceiverQuery Receiver { get; set; } = new ReceiverQuery();
}
#region Queries
/// <summary>
///
/// </summary>
public record EnvelopeQuery()
{
/// <summary>
///
/// </summary>
public string Uuid { get; set; } = null!;
};
/// <summary>
///
/// </summary>
public record ReceiverQuery()
{
/// <summary>
///
/// </summary>
public string Signature { get; set; } = null!;
};
#endregion
/// <summary>
///
/// </summary>
@@ -46,8 +76,23 @@ public static class ReceiverAlreadySignedQueryExtensions
/// <param name="key"></param>
/// <param name="cancel"></param>
/// <returns></returns>
public static Task<bool> ReceiverAlreadySigned(this IMediator mediator, string key, CancellationToken cancel = default)
public static Task<bool> IsSignedAsync(this IMediator mediator, string key, CancellationToken cancel = default)
=> mediator.Send(new ReceiverAlreadySignedQuery { Key = key }, cancel);
/// <summary>
///
/// </summary>
/// <param name="mediator"></param>
/// <param name="uuid"></param>
/// <param name="signature"></param>
/// <param name="cancel"></param>
/// <returns></returns>
public static Task<bool> IsSignedAsync(this IMediator mediator, string uuid, string signature, CancellationToken cancel = default)
=> mediator.Send(new ReceiverAlreadySignedQuery
{
Envelope = new() { Uuid = uuid },
Receiver = new() { Signature = signature }
}, cancel);
}
/// <summary>
@@ -75,8 +120,8 @@ public class ReceiverAlreadySignedQueryHandler : IRequestHandler<ReceiverAlready
public async Task<bool> Handle(ReceiverAlreadySignedQuery request, CancellationToken cancel = default)
{
return await _repo.Read()
.Where(er => er.Envelope.Uuid == request.EnvelopeUuid)
.Where(er => er.Receiver.Signature == request.ReceiverSignature)
.Where(er => er.Envelope.Uuid == request.Envelope.Uuid)
.Where(er => er.Receiver.Signature == request.Receiver.Signature)
.Where(er => er.Envelope.History.Any(hist => hist.Status == Constants.EnvelopeStatus.DocumentSigned))
.AnyAsync(cancel);
}

View File

@@ -1,22 +0,0 @@
namespace EnvelopeGenerator.Application.Exceptions;
/// <summary>
/// Represents an exception that is thrown when a bad request is encountered.
/// </summary>
public class BadRequestException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="BadRequestException"/> class.
/// </summary>
public BadRequestException()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="BadRequestException"/> class with a specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public BadRequestException(string? message) : base(message)
{
}
}

View File

@@ -1,22 +0,0 @@
namespace EnvelopeGenerator.Application.Exceptions;
/// <summary>
/// Represents an exception that is thrown when a requested resource is not found.
/// </summary>
public class NotFoundException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="NotFoundException"/> class.
/// </summary>
public NotFoundException()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="NotFoundException"/> class with a specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public NotFoundException(string? message) : base(message)
{
}
}

View File

@@ -1,4 +1,4 @@
using EnvelopeGenerator.Application.Exceptions;
using DigitalData.Core.Exceptions;
namespace EnvelopeGenerator.Application.Extensions;
@@ -9,32 +9,34 @@ public static class TaskExtensions
{
/// <summary>
/// Awaits the specified task and ensures that the result is not <c>null</c>.
/// If the result is <c>null</c>, a <see cref="NotFoundException"/> is thrown.
/// If the result is <c>null</c>, the exception created by factory-method is thrown.
/// </summary>
/// <typeparam name="T">The type of the result.</typeparam>
/// <typeparam name="TException">The type of the exception.</typeparam>
/// <param name="task">The task to await.</param>
/// <param name="exceptionMessage">Optional custom exception message.</param>
/// <param name="factory">Exception provider</param>
/// <returns>The awaited result if not <c>null</c>.</returns>
/// <exception cref="NotFoundException">Thrown if the result is <c>null</c>.</exception>
public static async Task<T> ThrowIfNull<T>(this Task<T?> task, string? exceptionMessage = null)
/// <exception>Thrown if the result is <c>null</c>.</exception>
public static async Task<T> ThrowIfNull<T, TException>(this Task<T?> task, Func<TException> factory) where TException : Exception
{
var result = await task;
return result ?? throw new NotFoundException(exceptionMessage);
return result ?? throw factory();
}
/// <summary>
/// Awaits the specified task and ensures that the result is not <c>empty</c>.
/// If the result contains no elements, a <see cref="NotFoundException"/> is thrown.
/// If the result contains no elements, the exception created by factory-method is thrown.
/// </summary>
/// <typeparam name="T">The element type of the collection.</typeparam>
/// <typeparam name="TException">The type of the exception.</typeparam>
/// <param name="task">The task to await.</param>
/// <param name="exceptionMessage">Optional custom exception message.</param>
/// <param name="factory">Exception provider</param>
/// <returns>The awaited collection if it is not <c>null</c> or empty.</returns>
/// <exception cref="NotFoundException">Thrown if the result is <c>null</c> or empty.</exception>
public static async Task<IEnumerable<T>> ThrowIfNull<T>(this Task<IEnumerable<T>> task, string? exceptionMessage = null)
public static async Task<IEnumerable<T>> ThrowIfNull<T, TException>(this Task<IEnumerable<T>> task, Func<TException> factory) where TException : Exception
{
var result = await task;
return result?.Any() ?? false ? result : throw new NotFoundException(exceptionMessage);
return result?.Any() ?? false ? result : throw factory();
}
/// <summary>
@@ -51,3 +53,26 @@ public static class TaskExtensions
return act(res);
}
}
/// <summary>
///
/// </summary>
public static class Exceptions
{
/// <summary>
///
/// </summary>
public static NotFoundException NotFound() => new();
/// <summary>
///
/// </summary>
/// <returns></returns>
public static BadRequestException BadRequest() => new();
/// <summary>
///
/// </summary>
/// <returns></returns>
public static ForbiddenException Forbidden() => new();
}

View File

@@ -0,0 +1,81 @@
using DigitalData.Core.Abstraction.Application.Repository;
using EnvelopeGenerator.Domain;
using EnvelopeGenerator.Domain.Entities;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace EnvelopeGenerator.Application.Histories.Commands;
/// <summary>
///
/// </summary>
public record CreateHistoryCommand : IRequest<long?>
{
/// <summary>
///
/// </summary>
public int EnvelopeId { get; set; }
/// <summary>
///
/// </summary>
public string UserReference { get; set; } = null!;
/// <summary>
///
/// </summary>
public Constants.EnvelopeStatus Status { get; set; }
/// <summary>
///
/// </summary>
public DateTime AddedWhen { get; } = DateTime.Now;
/// <summary>
///
/// </summary>
public DateTime ActionDate => AddedWhen;
/// <summary>
///
/// </summary>
public string? Comment { get; set; }
}
/// <summary>
///
/// </summary>
public class CreateHistoryCommandHandler : IRequestHandler<CreateHistoryCommand, long?>
{
private readonly IRepository<EnvelopeHistory> _repo;
/// <summary>
///
/// </summary>
/// <param name="repo"></param>
public CreateHistoryCommandHandler(IRepository<EnvelopeHistory> repo)
{
_repo = repo;
}
/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <param name="cancel"></param>
/// <returns></returns>
public async Task<long?> Handle(CreateHistoryCommand request, CancellationToken cancel)
{
// create entitiy
await _repo.CreateAsync(request, cancel);
// check if created
var record = await _repo.ReadOnly()
.Where(h => h.EnvelopeId == request.EnvelopeId)
.Where(h => h.UserReference == request.UserReference)
.Where(h => h.ActionDate == request.ActionDate)
.SingleOrDefaultAsync(cancel);
return record?.Id;
}
}

View File

@@ -1,4 +1,5 @@
using AutoMapper;
using EnvelopeGenerator.Application.Histories.Commands;
using EnvelopeGenerator.Application.Histories.Queries.Read;
using EnvelopeGenerator.Domain.Entities;
@@ -15,5 +16,6 @@ public class MappingProfile: Profile
public MappingProfile()
{
CreateMap<EnvelopeHistory, ReadHistoryResponse>();
CreateMap<CreateHistoryCommand, EnvelopeHistory>();
}
}

View File

@@ -1,6 +1,6 @@
using AutoMapper;
using EnvelopeGenerator.Application.Interfaces.Repositories;
using EnvelopeGenerator.Application.Exceptions;
using DigitalData.Core.Exceptions;
using MediatR;
namespace EnvelopeGenerator.Application.Histories.Queries.Read;

View File

@@ -1,6 +1,6 @@
using Dapper;
using EnvelopeGenerator.Application.Interfaces.SQLExecutor;
using EnvelopeGenerator.Application.Exceptions;
using DigitalData.Core.Exceptions;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.SQL;

View File

@@ -41,6 +41,12 @@ public class DocumentStatus
[Column("VALUE", TypeName = "nvarchar(max)")]
public string Value { get; set; }
[ForeignKey("EnvelopeId")]
public virtual Envelope Envelope { get; set; }
[ForeignKey("ReceiverId")]
public virtual Receiver Receiver { get; set; }
}
#if NETFRAMEWORK

View File

@@ -38,14 +38,28 @@ public class EnvelopeHistory
public DateTime AddedWhen { get; set; }
[Column("ACTION_DATE", TypeName = "datetime")]
public DateTime ActionDate { get; set; } = DateTime.Now;
public DateTime? ActionDate { get; set; } = DateTime.Now;
[Column("COMMENT", TypeName = "nvarchar(max)")]
public string Comment { get; set; }
public string
#if NET
?
#endif
Comment { get; set; }
public virtual User Sender { get; set; }
public virtual User
#if NET
?
#endif
Sender
{ get; set; }
public virtual Receiver Receiver { get; set; }
public virtual Receiver
#if NET
?
#endif
Receiver
{ get; set; }
#if NETFRAMEWORK
[NotMapped]

View File

@@ -10,7 +10,7 @@ using EnvelopeGenerator.Application.Dto;
using MediatR;
using System.Threading.Tasks;
using DigitalData.UserManager.Application.Services;
using EnvelopeGenerator.Application.Exceptions;
using DigitalData.Core.Exceptions;
namespace EnvelopeGenerator.GeneratorAPI.Controllers;

View File

@@ -1,6 +1,6 @@
namespace EnvelopeGenerator.GeneratorAPI.Middleware;
using EnvelopeGenerator.Application.Exceptions;
using DigitalData.Core.Exceptions;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using System.Net;

View File

@@ -97,10 +97,17 @@ public class EGDbContext : DbContext, IUserManagerDbContext, IMailDbContext
modelBuilder.Entity<DocumentReceiverElement>();
modelBuilder.Entity<DocumentStatus>();
modelBuilder.Entity<EmailTemplate>();
modelBuilder.Entity<Envelope>();
modelBuilder.Entity<Envelope>()
.HasIndex(e => e.Uuid)
.IsUnique();
modelBuilder.Entity<EnvelopeHistory>();
modelBuilder.Entity<EnvelopeType>();
modelBuilder.Entity<Receiver>();
modelBuilder.Entity<Receiver>()
.HasIndex(e => e.Signature)
.IsUnique();
modelBuilder.Entity<Receiver>()
.HasIndex(e => e.EmailAddress)
.IsUnique();
modelBuilder.Entity<EmailOut>();
// Configure the one-to-many relationship of Envelope
@@ -145,6 +152,24 @@ public class EGDbContext : DbContext, IUserManagerDbContext, IMailDbContext
.HasForeignKey(erro => erro.AddedWho)
.HasPrincipalKey(r => r.EmailAddress);
modelBuilder.Entity<DocumentStatus>()
.HasOne(ds => ds.Envelope)
.WithMany()
.HasForeignKey(ds => ds.EnvelopeId)
.HasPrincipalKey(e => e.Uuid);
modelBuilder.Entity<DocumentStatus>()
.HasOne(ds => ds.Receiver)
.WithMany()
.HasForeignKey(ds => ds.ReceiverId)
.HasPrincipalKey(e => e.Signature);
modelBuilder.Entity<DocumentStatus>()
.HasOne(ds => ds.Receiver)
.WithMany()
.HasForeignKey(ds => ds.ReceiverId)
.HasPrincipalKey(e => e.EmailAddress);
// Configure entities to handle database triggers
void AddTrigger<T>() where T : class => _triggers
.Where(t => t.Key == typeof(T).Name)

View File

@@ -8,8 +8,8 @@
<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.66" />
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.1.0" />
<PackageReference Include="DigitalData.Core.Infrastructure" Version="2.2.0" />
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.2.1" />
<PackageReference Include="DigitalData.Core.Infrastructure" Version="2.3.1" />
<PackageReference Include="DigitalData.Core.Infrastructure.AutoMapper" Version="1.0.3" />
<PackageReference Include="DigitalData.EmailProfilerDispatcher" Version="3.1.1" />
<PackageReference Include="UserManager" Version="1.1.3" />

View File

@@ -2,7 +2,7 @@
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Application.Interfaces.Repositories;
using Microsoft.EntityFrameworkCore;
using EnvelopeGenerator.Application.Exceptions;
using DigitalData.Core.Exceptions;
using EnvelopeGenerator.Domain;
namespace EnvelopeGenerator.Infrastructure.Repositories;

View File

@@ -23,7 +23,7 @@
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.1.0" />
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.2.1" />
<PackageReference Include="DigitalData.Core.Abstractions" Version="4.0.0" />
<PackageReference Include="DigitalData.Core.API" Version="2.2.1" />
<PackageReference Include="DigitalData.Core.Application" Version="3.4.0" />

View File

@@ -7,10 +7,13 @@ using EnvelopeGenerator.Extensions;
using EnvelopeGenerator.Application.Interfaces.Services;
using static EnvelopeGenerator.Domain.Constants;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Domain;
using DigitalData.Core.Abstraction.Application.DTO;
using EnvelopeGenerator.Web.Extensions;
using MediatR;
using System.Dynamic;
using EnvelopeGenerator.Application.EnvelopeReceivers.Queries;
using EnvelopeGenerator.Application.DocStatus.Commands;
using Newtonsoft.Json;
namespace EnvelopeGenerator.Web.Controllers;
@@ -47,34 +50,25 @@ public class EnvelopeController : BaseController
[Authorize(Roles = ReceiverRole.FullyAuth)]
[HttpPost("{envelopeKey}")]
[Obsolete("Use MediatR")]
public async Task<IActionResult> Update(string envelopeKey, int index)
public async Task<IActionResult> CreateOrUpdate([FromRoute] string envelopeKey, int index, [FromBody] ExpandoObject annotations, CancellationToken cancel = default)
{
envelopeKey = _urlEncoder.Encode(envelopeKey);
// get claims
var signature = User.GetAuthReceiverSignature();
var uuid = User.GetAuthEnvelopeUuid();
var authSignature = User.GetAuthReceiverSignature();
if (authSignature != envelopeKey.GetReceiverSignature())
return Unauthorized();
EnvelopeReceiver response = await envelopeService.LoadEnvelope(envelopeKey);
// Again check if receiver has already signed
if (envelopeService.ReceiverAlreadySigned(response.Envelope, response.Receiver.Id) == true)
if (signature is null || uuid is null)
{
return Problem(statusCode: 403);
_logger.LogError("Authorization failed: authenticated user does not have a valid signature or envelope UUID.");
return Unauthorized("User authentication is incomplete. Missing required claims for processing this request.");
}
var document = envelopeService.GetDocument(index, envelopeKey);
// Again check if receiver has already signed
if (await _mediator.IsSignedAsync(uuid, signature, cancel))
return Problem(statusCode: 403);
string? annotationData = await envelopeService.EnsureValidAnnotationData(Request);
await _mediator.SignDocAsync(uuid, signature, JsonConvert.SerializeObject(annotations), cancel);
envelopeService.InsertDocumentStatus(new Domain.Entities.DocumentStatus()
{
EnvelopeId = response.Envelope.Id,
ReceiverId = response.Receiver.Id,
Value = annotationData,
Status = Constants.DocumentStatus.Signed
});
EnvelopeReceiver response = await envelopeService.LoadEnvelope(envelopeKey);
var signResult = actionService?.SignEnvelope(response.Envelope, ReceiverVM.From(response));

View File

@@ -381,7 +381,7 @@ public class HomeController : ViewControllerBase
if(!isExisting)
return this.ViewEnvelopeNotFound();
var signed = await _mediator.ReceiverAlreadySigned(envelopeReceiverId, cancel);
var signed = await _mediator.IsSignedAsync(envelopeReceiverId, cancel);
if (signed)
return base.Redirect($"/EnvelopeKey/{envelopeReceiverId}/Locked");

View File

@@ -6,6 +6,7 @@ using DigitalData.Core.Abstraction.Application.DTO;
using EnvelopeGenerator.Application.EnvelopeReceivers.Queries;
using MediatR;
using EnvelopeGenerator.Application.Extensions;
using DigitalData.Core.Exceptions;
namespace EnvelopeGenerator.Web.Controllers.Test;
@@ -26,7 +27,7 @@ public class TestEnvelopeReceiverController : ControllerBase
[HttpGet]
public async Task<IActionResult> Get([FromQuery] ReadEnvelopeReceiverQuery q, CancellationToken cancel)
=> Ok(await _mediator.Send(q, cancel).ThrowIfNull());
=> Ok(await _mediator.Send(q, cancel).ThrowIfNull(Exceptions.NotFound));
[Obsolete("Use MediatR")]
[HttpGet("verify-access-code/{envelope_receiver_id}")]

View File

@@ -277,7 +277,6 @@ class App {
try {
const json = await iJSON
const postEnvelopeResult = await this.Network.postEnvelope(
this.envelopeKey,
this.currentDocument.id,
json
)

View File

@@ -15,8 +15,8 @@
* @param {any} documentId
* @param {any} json
*/
async postEnvelope(envelopeKey, documentId, json) {
return this.postRequest(`/api/envelope/${envelopeKey}?index=${documentId}`, json)
async postEnvelope(documentId, json) {
return this.postRequest(`/api/envelope?index=${documentId}`, json)
.then(this.wrapJsonResponse.bind(this))
}