Add GetAnnotsOfReceiver method to AnnotationController

Introduced the `GetAnnotsOfReceiver` method in `AnnotationController` to handle HTTP GET requests for retrieving receiver-specific annotations. The method enforces authorization using the `Receiver` policy, fetches the document via a mediator query, and filters signatures based on the current receiver. Returns appropriate HTTP responses for empty documents or missing signatures.

Added new `using` directives for required dependencies and reorganized imports for better readability. Included a `TODO` comment for potential future updates.
This commit is contained in:
2026-06-06 18:07:03 +02:00
parent e52972ee9b
commit 76ce8a44b3

View File

@@ -1,16 +1,19 @@
using DigitalData.Core.Abstraction.Application.DTO;
using DigitalData.Core.Exceptions;
using EnvelopeGenerator.API.Extensions;
using EnvelopeGenerator.Application.Common.Dto;
using EnvelopeGenerator.Application.Common.Extensions;
using EnvelopeGenerator.Application.Common.Interfaces.Services;
using EnvelopeGenerator.Application.Common.Notifications.DocSigned;
using EnvelopeGenerator.Application.Documents.Queries;
using EnvelopeGenerator.Application.EnvelopeReceivers.Queries;
using EnvelopeGenerator.Application.Histories.Queries;
using EnvelopeGenerator.Domain.Constants;
using EnvelopeGenerator.API.Extensions;
using MediatR;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Mvc;
namespace EnvelopeGenerator.API.Controllers;
@@ -115,4 +118,32 @@ public class AnnotationController : ControllerBase
_logger.LogNotice(histRes.Notices);
return StatusCode(500, histRes.Messages);
}
//TODO: update to use
/// <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);
}
}