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>
|
/// <summary>
|
||||||
///
|
/// Gets the document for the specified envelope key.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="envelopeKey"></param>
|
/// <param name="envelopeKey"></param>
|
||||||
/// <param name="cancel"></param>
|
/// <param name="cancel"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
[Authorize(Policy = AuthPolicy.Receiver)]
|
||||||
[HttpGet("{envelopeKey}")]
|
[HttpGet("{envelopeKey}")]
|
||||||
public async Task<IActionResult> GetDocumentOfReceiver(string envelopeKey, CancellationToken cancel)
|
public async Task<IActionResult> GetDocumentOfReceiver(string envelopeKey, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
var envelopeIdStr = User.FindFirst(EnvelopeClaimNames.EnvelopeId)?.Value;
|
int envelopeId = User.GetEnvelopeIdOfReceiver();
|
||||||
|
|
||||||
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.");
|
|
||||||
}
|
|
||||||
|
|
||||||
var senderDoc = await mediator.Send(new ReadDocumentQuery() { EnvelopeId = envelopeId }, cancel);
|
var senderDoc = await mediator.Send(new ReadDocumentQuery() { EnvelopeId = envelopeId }, cancel);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user