Compare commits
16 Commits
811656c4ca
...
f34770931f
| Author | SHA1 | Date | |
|---|---|---|---|
| f34770931f | |||
| 78100ef24f | |||
| 99083a68aa | |||
| 0939e57c56 | |||
| 00bdfeb9bb | |||
| cced0e5579 | |||
| 82150290d2 | |||
| fb7fd47a2a | |||
| 20b6b328f5 | |||
| fb07d9151f | |||
| a3bc26bd08 | |||
| e1f793e571 | |||
| 86d8fcda07 | |||
| 2f8401073f | |||
| 85a855fe64 | |||
| 996b544633 |
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
22
EnvelopeGenerator.Application/DocStatus/MappingProfile.cs
Normal file
22
EnvelopeGenerator.Application/DocStatus/MappingProfile.cs
Normal 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>();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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}")]
|
||||
|
||||
@@ -277,7 +277,6 @@ class App {
|
||||
try {
|
||||
const json = await iJSON
|
||||
const postEnvelopeResult = await this.Network.postEnvelope(
|
||||
this.envelopeKey,
|
||||
this.currentDocument.id,
|
||||
json
|
||||
)
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user