From ecc509919cd15cb56e146437607c90b2568becfb Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 23 Sep 2026 15:32:58 +0200 Subject: [PATCH] feat: add GetDocumentOfSenderAsync to EnvelopeReceiverPageDataService Loads the PDF bytes for a given envelope on behalf of the authenticated sender (uses SenderId() claim extension). Throws NotFoundException when no document data is available so callers can surface a typed error. --- .../Services/EnvelopeReceiverPageDataService.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Services/EnvelopeReceiverPageDataService.cs b/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Services/EnvelopeReceiverPageDataService.cs index 73681da3..286ce6db 100644 --- a/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Services/EnvelopeReceiverPageDataService.cs +++ b/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Services/EnvelopeReceiverPageDataService.cs @@ -1,5 +1,6 @@ using System.Security.Claims; using System.Text.Json; +using DigitalData.Core.Exceptions; using EnvelopeGenerator.Application.Common.Dto; using EnvelopeGenerator.Application.Common.Dto.EnvelopeReceiver; using EnvelopeGenerator.Application.Documents.Queries; @@ -37,6 +38,17 @@ public class EnvelopeReceiverPageDataService( return document.ByteData; } + /// + /// Loads the PDF document bytes for the authenticated receiver. + /// + public async Task GetDocumentOfSenderAsync(ClaimsPrincipal user, int envelopeId, CancellationToken cancellationToken = default) + { + var document = await mediator.Send(new ReadDocumentQuery(EnvelopeId: envelopeId, UserId: user.SenderId()), cancellationToken); + return (document.ByteData is byte[] data && data.Length > 0) + ? data + : throw new NotFoundException($"Document for envelope {envelopeId} not found."); + } + /// /// Loads the current receiver's signature placeholders. ///