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. ///