82 lines
3.1 KiB
C#
82 lines
3.1 KiB
C#
using DigitalData.Core.API;
|
|
using EnvelopeGenerator.Application.Extensions;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using EnvelopeGenerator.Application.Interfaces.Services;
|
|
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;
|
|
|
|
[Route("api/test/[controller]")]
|
|
[ApiController]
|
|
public class TestEnvelopeReceiverController : ControllerBase
|
|
{
|
|
private readonly IMediator _mediator;
|
|
[Obsolete("Use MediatR")]
|
|
private readonly IEnvelopeReceiverService _service;
|
|
|
|
[Obsolete("Use MediatR")]
|
|
public TestEnvelopeReceiverController(ILogger<TestEnvelopeReceiverController> logger, IEnvelopeReceiverService service, IMediator mediator, IEnvelopeReceiverService erService)
|
|
{
|
|
_mediator = mediator;
|
|
_service = erService;
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> Get([FromQuery] ReadEnvelopeReceiverQuery q, CancellationToken cancel)
|
|
=> Ok(await _mediator.Send(q, cancel).ThrowIfEmpty(Exceptions.NotFound));
|
|
|
|
[Obsolete("Use MediatR")]
|
|
[HttpGet("verify-access-code/{envelope_receiver_id}")]
|
|
public async Task<IActionResult> VerifyAccessCode([FromRoute] string envelope_receiver_id, [FromQuery] string access_code)
|
|
{
|
|
var verification = await _service.VerifyAccessCodeAsync(envelopeReceiverId:envelope_receiver_id, accessCode: access_code);
|
|
|
|
if (verification.IsSuccess)
|
|
return Ok(verification);
|
|
else if (verification.HasFlag(Flag.SecurityBreach))
|
|
return Forbid();
|
|
else if (verification.HasFlag(Flag.SecurityBreachOrDataIntegrity))
|
|
return Conflict();
|
|
else
|
|
return this.InnerServiceError(verification);
|
|
}
|
|
|
|
[Obsolete("Use MediatR")]
|
|
[HttpGet("e-r-id/{envelope_receiver_id}")]
|
|
public async Task<IActionResult> GetByEnvelopeReceiverId([FromRoute] string envelope_receiver_id)
|
|
{
|
|
var er_result = await _service.ReadByEnvelopeReceiverIdAsync(envelopeReceiverId: envelope_receiver_id);
|
|
if (er_result.IsSuccess)
|
|
return Ok(er_result);
|
|
else
|
|
return this.InnerServiceError(er_result);
|
|
}
|
|
|
|
[HttpGet("decode")]
|
|
public IActionResult DecodeEnvelopeReceiverId(string envelopeReceiverId, bool isReadOnly = false)
|
|
{
|
|
if (isReadOnly)
|
|
{
|
|
var readOnlyId = envelopeReceiverId.DecodeEnvelopeReceiverReadOnlyId();
|
|
return Ok(new { readOnlyId });
|
|
}
|
|
else
|
|
{
|
|
var (EnvelopeUuid, ReceiverSignature) = envelopeReceiverId.DecodeEnvelopeReceiverId();
|
|
return Ok(new { uuid = EnvelopeUuid, signature = ReceiverSignature });
|
|
}
|
|
}
|
|
|
|
[HttpGet("encode")]
|
|
public IActionResult EncodeEnvelopeReceiverId(string? uuid = null, string? signature = null, long? readOnlyId = null)
|
|
{
|
|
if(readOnlyId is long readOnlyId_long)
|
|
return Ok(readOnlyId_long.ToEnvelopeKey());
|
|
else
|
|
return Ok((uuid ?? string.Empty, signature ?? string.Empty).ToEnvelopeKey());
|
|
}
|
|
} |