update to create key by EncodeEnvelopeReceiverId
This commit is contained in:
@@ -1,30 +1,38 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using System.Text;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Application.Extensions
|
namespace EnvelopeGenerator.Application.Extensions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides extension methods for decoding and extracting information from an envelope receiver ID.
|
||||||
|
/// </summary>
|
||||||
|
public static class EncodingExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides extension methods for decoding and extracting information from an envelope receiver ID.
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class EncodingExtensions
|
/// <param name="readOnlyId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string EncodeEnvelopeReceiverId(this long readOnlyId)
|
||||||
{
|
{
|
||||||
public static string EncodeEnvelopeReceiverId(this long readOnlyId)
|
//The random number is used as a salt to increase security but it is not saved in the database.
|
||||||
{
|
string combinedString = $"{Random.Shared.Next()}::{readOnlyId}::{Random.Shared.Next()}";
|
||||||
//The random number is used as a salt to increase security but it is not saved in the database.
|
byte[] bytes = Encoding.UTF8.GetBytes(combinedString);
|
||||||
string combinedString = $"{Random.Shared.Next()}::{readOnlyId}::{Random.Shared.Next()}";
|
string base64String = Convert.ToBase64String(bytes);
|
||||||
byte[] bytes = Encoding.UTF8.GetBytes(combinedString);
|
|
||||||
string base64String = Convert.ToBase64String(bytes);
|
|
||||||
|
|
||||||
return base64String;
|
return base64String;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string EncodeEnvelopeReceiverId(this (string envelopeUuid, string receiverSignature) input)
|
/// <summary>
|
||||||
{
|
///
|
||||||
string combinedString = $"{input.envelopeUuid}::{input.receiverSignature}";
|
/// </summary>
|
||||||
byte[] bytes = Encoding.UTF8.GetBytes(combinedString);
|
/// <param name="input"></param>
|
||||||
string base64String = Convert.ToBase64String(bytes);
|
/// <returns></returns>
|
||||||
|
public static string EncodeEnvelopeReceiverId(this (string envelopeUuid, string receiverSignature) input)
|
||||||
|
{
|
||||||
|
string combinedString = $"{input.envelopeUuid}::{input.receiverSignature}";
|
||||||
|
byte[] bytes = Encoding.UTF8.GetBytes(combinedString);
|
||||||
|
string base64String = Convert.ToBase64String(bytes);
|
||||||
|
|
||||||
return base64String;
|
return base64String;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
using DigitalData.Core.Abstraction.Application.Repository;
|
using AutoMapper;
|
||||||
|
using DigitalData.Core.Abstraction.Application.Repository;
|
||||||
|
using EnvelopeGenerator.Application.Dto.Receiver;
|
||||||
using EnvelopeGenerator.Domain.Entities;
|
using EnvelopeGenerator.Domain.Entities;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@@ -13,7 +15,7 @@ namespace EnvelopeGenerator.Application.Receivers.Commands;
|
|||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ApiExplorerSettings(IgnoreApi = true)]
|
[ApiExplorerSettings(IgnoreApi = true)]
|
||||||
public record CreateReceiverCommand : IRequest<(int Id, bool AlreadyExists)>
|
public record CreateReceiverCommand : IRequest<(ReceiverReadDto Receiver, bool AlreadyExists)>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@@ -52,20 +54,23 @@ public record CreateReceiverCommand : IRequest<(int Id, bool AlreadyExists)>
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CreateReceiverCommandHandler : IRequestHandler<CreateReceiverCommand, (int Id, bool AlreadyExists)>
|
public class CreateReceiverCommandHandler : IRequestHandler<CreateReceiverCommand, (ReceiverReadDto Receiver, bool AlreadyExists)>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly IRepository<Receiver> _repo;
|
private readonly IRepository<Receiver> _repo;
|
||||||
|
|
||||||
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="repo"></param>
|
/// <param name="repo"></param>
|
||||||
public CreateReceiverCommandHandler(IRepository<Receiver> repo)
|
public CreateReceiverCommandHandler(IRepository<Receiver> repo, IMapper mapper)
|
||||||
{
|
{
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
|
_mapper = mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -74,7 +79,7 @@ public class CreateReceiverCommandHandler : IRequestHandler<CreateReceiverComman
|
|||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="cancel"></param>
|
/// <param name="cancel"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<(int Id, bool AlreadyExists)> Handle(CreateReceiverCommand request, CancellationToken cancel)
|
public async Task<(ReceiverReadDto Receiver, bool AlreadyExists)> Handle(CreateReceiverCommand request, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
var receiver = await _repo.ReadOnly()
|
var receiver = await _repo.ReadOnly()
|
||||||
.Where(r => r.EmailAddress == request.EmailAddress)
|
.Where(r => r.EmailAddress == request.EmailAddress)
|
||||||
@@ -85,6 +90,7 @@ public class CreateReceiverCommandHandler : IRequestHandler<CreateReceiverComman
|
|||||||
if (!alreadyExists)
|
if (!alreadyExists)
|
||||||
receiver = await _repo.CreateAsync(request, cancel);
|
receiver = await _repo.CreateAsync(request, cancel);
|
||||||
|
|
||||||
return (receiver!.Id, alreadyExists);
|
var receiverDto = _mapper.Map<ReceiverReadDto>(receiver);
|
||||||
|
return (receiverDto, alreadyExists);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using EnvelopeGenerator.Application.Histories.Commands;
|
using EnvelopeGenerator.Application.Extensions;
|
||||||
|
using EnvelopeGenerator.Application.Histories.Commands;
|
||||||
using EnvelopeGenerator.Application.Histories.Queries;
|
using EnvelopeGenerator.Application.Histories.Queries;
|
||||||
using EnvelopeGenerator.Domain.Constants;
|
using EnvelopeGenerator.Domain.Constants;
|
||||||
|
|
||||||
@@ -25,13 +26,14 @@ public class HistoryTests : TestBase
|
|||||||
/// Arrange
|
/// Arrange
|
||||||
// Create envelope
|
// Create envelope
|
||||||
var createEnvelopeCmd = FakeCreateEnvelopeCommand;
|
var createEnvelopeCmd = FakeCreateEnvelopeCommand;
|
||||||
var envelope = await Mediator.Send(createEnvelopeCmd);
|
var envelope = await Mediator.Send(createEnvelopeCmd).ThrowIfNull(Exceptions.NotFound);
|
||||||
|
|
||||||
// Create receiver
|
// Create receiver
|
||||||
var createReceiverCmd = this.CreateReceiverCommand();
|
var createReceiverCmd = this.CreateReceiverCommand();
|
||||||
(int receiverId, _) = await Mediator.Send(createReceiverCmd);
|
(var receiver, _) = await Mediator.Send(createReceiverCmd);
|
||||||
|
|
||||||
|
var key = (envelope.Uuid, receiver.Signature).EncodeEnvelopeReceiverId();
|
||||||
|
|
||||||
var key = string.Empty;
|
|
||||||
var createCmd = Fake.Provider.CreateHistoryCommand(key);
|
var createCmd = Fake.Provider.CreateHistoryCommand(key);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|||||||
Reference in New Issue
Block a user