From ea6f3e61be108912e4fa3eddfe28486d9662e9f5 Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 3 Jun 2026 10:31:29 +0200 Subject: [PATCH] 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. --- .../Controllers/DocumentController.cs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/EnvelopeGenerator.API/Controllers/DocumentController.cs b/EnvelopeGenerator.API/Controllers/DocumentController.cs index 675ee7e1..74049871 100644 --- a/EnvelopeGenerator.API/Controllers/DocumentController.cs +++ b/EnvelopeGenerator.API/Controllers/DocumentController.cs @@ -62,25 +62,16 @@ public class DocumentController(IMediator mediator, IAuthorizationService authSe } /// - /// + /// Gets the document for the specified envelope key. /// /// /// /// + [Authorize(Policy = AuthPolicy.Receiver)] [HttpGet("{envelopeKey}")] public async Task 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);