Add GetDocumentOfReceiver method to DocumentController
The `GetDocumentOfReceiver` method was introduced to handle retrieving a document for a specified envelope key. It is secured with the `[Authorize(Policy = AuthPolicy.Receiver)]` attribute and responds to HTTP GET requests with a route parameter `envelopeKey`. The previous logic for extracting and validating the `envelopeId` from user claims was removed. This was replaced with a call to `User.GetEnvelopeIdOfReceiver()` for improved clarity and maintainability. The method uses the `mediator` to send a `ReadDocumentQuery` and returns a `NotFound` response if the document's `ByteData` is empty.
This commit is contained in:
@@ -62,25 +62,16 @@ public class DocumentController(IMediator mediator, IAuthorizationService authSe
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Gets the document for the specified envelope key.
|
||||
/// </summary>
|
||||
/// <param name="envelopeKey"></param>
|
||||
/// <param name="cancel"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize(Policy = AuthPolicy.Receiver)]
|
||||
[HttpGet("{envelopeKey}")]
|
||||
public async Task<IActionResult> GetDocumentOfReceiver(string envelopeKey, CancellationToken cancel)
|
||||
{
|
||||
var envelopeIdStr = User.FindFirst(EnvelopeClaimNames.EnvelopeId)?.Value;
|
||||
|
||||
if (!int.TryParse(envelopeIdStr, out int envelopeId))
|
||||
{
|
||||
logger.LogError(
|
||||
"Inner service error: Failed to parse Envelope ID from claims. Claim '{ClaimName}' had an invalid or missing value: '{ClaimValue}'.",
|
||||
EnvelopeClaimNames.EnvelopeId,
|
||||
envelopeIdStr ?? "null");
|
||||
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "Inner service error: Invalid envelope claim.");
|
||||
}
|
||||
int envelopeId = User.GetEnvelopeIdOfReceiver();
|
||||
|
||||
var senderDoc = await mediator.Send(new ReadDocumentQuery() { EnvelopeId = envelopeId }, cancel);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user