The `GetAnnotsOfReceiver` method was removed from the `AnnotationController` class and moved to a newly introduced `SignatureController` class. The `SignatureController` is now a dedicated controller for handling signature-related endpoints, decorated with `[ApiController]` and `[Route("api/[controller]")]`.
The method's implementation remains largely unchanged, retaining its logic for retrieving and filtering signatures for a specific receiver. Dependency injection for `IMediator` was added to the `SignatureController` to handle the `ReadDocumentQuery`.
Additional `using` directives were added to `SignatureController.cs` to include necessary namespaces. A `TODO` comment remains in the method, indicating potential future updates.
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> GetAnnotsOfReceiver(string envelopeKey, CancellationToken cancel)
|
|
{
|
|
int envelopeId = User.GetEnvelopeIdOfReceiver();
|
|
|
|
int receiverId = User.GetReceiverIdOfReceiver();
|
|
|
|
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);
|
|
}
|
|
}
|