46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
using FastEndpoints;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using PyroFetes.DTO.Show.Request;
|
|
using PyroFetes.DTO.Show.Response;
|
|
|
|
namespace PyroFetes.Endpoints.Show;
|
|
|
|
public class GetShowEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<IdShowDto, ReadShowDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Get("/api/shows/{Id}");
|
|
AllowAnonymous();
|
|
}
|
|
|
|
public override async Task HandleAsync(IdShowDto req, CancellationToken ct)
|
|
{
|
|
if (!req.Id.HasValue)
|
|
{
|
|
await Send.NotFoundAsync(ct);
|
|
return;
|
|
}
|
|
|
|
var show = await pyroFetesDbContext.Shows
|
|
.Where(s => s.Id == req.Id.Value)
|
|
.Select(s => new ReadShowDto
|
|
{
|
|
Id = s.Id,
|
|
Name = s.Name,
|
|
Place = s.Place,
|
|
Description = s.Description,
|
|
PyrotechnicImplementationPlan = s.PyrotechnicImplementationPlan,
|
|
Date = s.Date.HasValue ? s.Date.Value.ToDateTime(TimeOnly.MinValue) : null
|
|
})
|
|
.FirstOrDefaultAsync(ct);
|
|
|
|
if (show is null)
|
|
{
|
|
await Send.NotFoundAsync(ct);
|
|
return;
|
|
}
|
|
|
|
await Send.OkAsync(show, ct);
|
|
}
|
|
}
|