WebApi + ClientApp, GraphQL, Reflection
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Events.FilesAPI.Features.Certificates.Download;
|
||||
using MediatR;
|
||||
|
||||
namespace Events.FilesAPI.Features.Certificates;
|
||||
|
||||
[ApiController]
|
||||
[Route("Registrations")]
|
||||
public class DownloadCertificateController : ControllerBase
|
||||
{
|
||||
private const string PdfContentType = "application/pdf";
|
||||
|
||||
[HttpGet("{id}/Certificate")]
|
||||
[ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> DownloadCertificate(
|
||||
int id,
|
||||
[FromServices] IMediator mediator,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
DownloadCertificateResult result = await mediator.Send(new DownloadCertificateQuery(id), cancellationToken);
|
||||
if (!result.RegistrationFound)
|
||||
return Problem(statusCode: StatusCodes.Status404NotFound, detail: $"Invalid id = {id}");
|
||||
|
||||
if (result.File == null)
|
||||
return Problem(statusCode: StatusCodes.Status404NotFound, detail: "Certificate could not be generated.");
|
||||
|
||||
return PhysicalFile(result.File.PhysicalPath, PdfContentType, result.File.FileName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user