71b7a53e59
Removes DateOnly/DateTime conversion boilerplate from all Show endpoints and adds the corresponding EF Core migration. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
47 lines
1.2 KiB
C#
47 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("/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,
|
|
CityId = s.CityId
|
|
})
|
|
.FirstOrDefaultAsync(ct);
|
|
|
|
if (show is null)
|
|
{
|
|
await Send.NotFoundAsync(ct);
|
|
return;
|
|
}
|
|
|
|
await Send.OkAsync(show, ct);
|
|
}
|
|
}
|