Files
EnvelopeGenerator/EnvelopeGenerator.Web/Controllers/DocumentController.cs
TekH ebed51b46a Refactor receiver roles: rename FullyAuth/PreAuth for clarity
Renamed receiver roles FullyAuth → Receiver.Full and PreAuth → Receiver.TFA across the codebase for improved clarity and consistency. Updated all usages, [Authorize] attributes, role checks, authentication logic, and authorization policies to use the new role names. Marked old constants as obsolete and pointed them to the new values. This change enhances code readability and groups receiver roles under the Receiver static class.
2026-02-06 10:49:28 +01:00

42 lines
1.5 KiB
C#

using DigitalData.Core.Exceptions;
using EnvelopeGenerator.Application.Common.Extensions;
using EnvelopeGenerator.Application.EnvelopeReceivers.Queries;
using EnvelopeGenerator.Domain.Constants;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace EnvelopeGenerator.Web.Controllers;
[Authorize(Roles = Role.ReceiverFull)]
[ApiController]
[Route("api/[controller]")]
public class DocumentController : ControllerBase
{
private readonly IMediator _mediator;
private readonly ILogger<DocumentController> _logger;
public DocumentController(IMediator mediator, ILogger<DocumentController> logger)
{
_mediator = mediator;
_logger = logger;
}
[HttpGet("{envelopeKey}")]
public async Task<IActionResult> GetDocument([FromRoute] string envelopeKey, CancellationToken cancel)
{
var envRcv = await _mediator.ReadEnvelopeReceiverAsync(envelopeKey, cancel) ?? throw new NotFoundException("Envelope Receiver is not found.");
var byteData = envRcv.Envelope?.Documents?.FirstOrDefault()?.ByteData;
if(byteData is null || byteData.Length == 0)
{
_logger.LogError("Document byte data is null or empty for envelope-receiver entity:\n{envelopeKey}.",
envRcv.ToJson(Format.Json.ForDiagnostics));
throw new NotFoundException("Document is empty.");
}
return File(byteData, "application/octet-stream");
}
}