b3612f5bec
- 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>
44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using FastEndpoints;
|
|
using PyroFetes.DTO.Show.Request;
|
|
using PyroFetes.DTO.Show.Response;
|
|
|
|
namespace PyroFetes.Endpoints.Show;
|
|
|
|
public class CreateShowEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateShowDto, ReadShowDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Post("/shows");
|
|
AllowAnonymous();
|
|
}
|
|
|
|
public override async Task HandleAsync(CreateShowDto req, CancellationToken ct)
|
|
{
|
|
var show = new PyroFetes.Models.Show
|
|
{
|
|
Name = req.Name ?? string.Empty,
|
|
Place = req.Place ?? string.Empty,
|
|
Description = req.Description,
|
|
PyrotechnicImplementationPlan = req.PyrotechnicImplementationPlan ?? string.Empty,
|
|
Date = req.Date.HasValue ? DateOnly.FromDateTime(req.Date.Value) : null,
|
|
CityId = req.CityId
|
|
};
|
|
|
|
pyroFetesDbContext.Shows.Add(show);
|
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
|
|
|
var result = new ReadShowDto
|
|
{
|
|
Id = show.Id,
|
|
Name = show.Name,
|
|
Place = show.Place,
|
|
Description = show.Description,
|
|
PyrotechnicImplementationPlan = show.PyrotechnicImplementationPlan,
|
|
Date = show.Date.HasValue ? show.Date.Value.ToDateTime(TimeOnly.MinValue) : null,
|
|
CityId = show.CityId
|
|
};
|
|
|
|
await Send.OkAsync(result, ct);
|
|
}
|
|
}
|