Replaced all EnvelopeGenerator.GeneratorAPI namespaces with EnvelopeGenerator.API across controllers, models, extensions, middleware, and annotation-related files. Updated using/import statements and namespace declarations accordingly. Added wwwroot folder to project file. Minor code adjustments made for consistency. This unifies API naming for improved clarity and maintainability.
44 lines
1.6 KiB
C#
44 lines
1.6 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.API.Controllers;
|
|
|
|
/// <summary>
|
|
/// Provides access to envelope documents for authenticated receivers.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Initializes a new instance of the <see cref="DocumentController"/> class.
|
|
/// </remarks>
|
|
[Authorize(Roles = ReceiverRole.FullyAuth)]
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class DocumentController(IMediator mediator, ILogger<DocumentController> logger) : ControllerBase
|
|
{
|
|
/// <summary>
|
|
/// Returns the document bytes for the specified envelope receiver key.
|
|
/// </summary>
|
|
/// <param name="query">Encoded envelope key.</param>
|
|
/// <param name="cancel">Cancellation token.</param>
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetDocument(ReadEnvelopeReceiverQuery query, CancellationToken cancel)
|
|
{
|
|
var envRcv = await mediator.Send(query, cancel).FirstAsync(Exceptions.NotFound);
|
|
|
|
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");
|
|
}
|
|
}
|