Finalisation endpoints
This commit is contained in:
45
PyroFetes/Endpoints/Show/GetShowEndpoint.cs
Normal file
45
PyroFetes/Endpoints/Show/GetShowEndpoint.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user