Renamed the method `GetAnnotsOfReceiver` to `Get` in the `SignatureController` class. This change simplifies the method name, making it more generic and potentially aligning with naming conventions or broader use cases.
58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
using EnvelopeGenerator.API.Extensions;
|
|
using EnvelopeGenerator.Application.Common.Dto;
|
|
using EnvelopeGenerator.Application.Common.Extensions;
|
|
using EnvelopeGenerator.Application.Documents.Queries;
|
|
using EnvelopeGenerator.Domain.Constants;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace EnvelopeGenerator.API.Controllers;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Authorize(Policy = AuthPolicy.Receiver)]
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class SignatureController : ControllerBase
|
|
{
|
|
private readonly IMediator _mediator;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of <see cref="SignatureController"/>.
|
|
/// </summary>
|
|
public SignatureController(IMediator mediator)
|
|
{
|
|
_mediator = mediator;
|
|
}
|
|
|
|
//TODO: update to use signature query
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="envelopeKey"></param>
|
|
/// <param name="cancel"></param>
|
|
/// <returns></returns>
|
|
[Authorize(Policy = AuthPolicy.Receiver)]
|
|
[HttpGet("{envelopeKey}")]
|
|
public async Task<IActionResult> Get(string envelopeKey, CancellationToken cancel)
|
|
{
|
|
int envelopeId = User.EnvelopeId();
|
|
|
|
int receiverId = User.ReceiverId();
|
|
|
|
var doc = await _mediator.Send(new ReadDocumentQuery() { EnvelopeId = envelopeId }, cancel);
|
|
|
|
if (doc.Elements is not IEnumerable<SignatureDto> docSignatures)
|
|
return NotFound("Document is empty.");
|
|
|
|
var rcvSignatures = docSignatures.Where(s => s.ReceiverId == receiverId).ToList();
|
|
|
|
if (rcvSignatures is null)
|
|
return NotFound("No signatures found for the current receiver.");
|
|
else
|
|
return Ok(rcvSignatures);
|
|
}
|
|
}
|