Files
PF3-fork/PyroFetes/Endpoints/Show/GetShowEndpoint.cs
T
cernont b3612f5bec Remove /api prefix from all routes and fix CityId FK constraint
- Strip /api prefix from all endpoint routes
- Make Show.CityId nullable (no longer required FK)
- Drop CityId FK constraint and alter column to NULL at startup via raw SQL
- Add migration MakeCityIdNullable for schema consistency
- Update Show DTOs to reflect nullable CityId

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-27 20:32:55 +02:00

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.HasValue ? s.Date.Value.ToDateTime(TimeOnly.MinValue) : null,
CityId = s.CityId
})
.FirstOrDefaultAsync(ct);
if (show is null)
{
await Send.NotFoundAsync(ct);
return;
}
await Send.OkAsync(show, ct);
}
}