66 lines
2.9 KiB
C#
66 lines
2.9 KiB
C#
using DigitalData.Core.API;
|
|
using DigitalData.Core.DTO;
|
|
using EnvelopeGenerator.Application.Contracts;
|
|
using EnvelopeGenerator.Application;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver;
|
|
|
|
namespace EnvelopeGenerator.Web.Controllers.Test
|
|
{
|
|
public class TestEnvelopeReceiverController : ReadControllerBase<IEnvelopeReceiverService, EnvelopeReceiverDto, EnvelopeReceiver, (int Envelope, int Receiver)>
|
|
{
|
|
public TestEnvelopeReceiverController(ILogger<TestEnvelopeReceiverController> logger, IEnvelopeReceiverService service) : base(logger, service)
|
|
{
|
|
}
|
|
|
|
[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);
|
|
}
|
|
|
|
[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 (Random1, ReadOnlyId, Random2) = envelopeReceiverId.DecodeEnvelopeReceiverReadOnlyId();
|
|
return Ok(new { random = new string?[] { Random1, Random2 }, readOnlyId = 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.EncodeEnvelopeReceiverId());
|
|
else
|
|
return Ok((uuid ?? string.Empty, signature ?? string.Empty).EncodeEnvelopeReceiverId());
|
|
}
|
|
}
|
|
} |