6c1330e570
- Register FastEndpoints, SwaggerDocument, DbContext in Program.cs - Add DbContextOptions constructor to PyroFetesDbContext - Add CityId to Show DTOs and endpoints (NOT NULL in DB) - Add F4T2NumberApproval/F4T2ExpirationDate to Staff DTOs and endpoints - Simplify DeleteShow to rely on DB cascade instead of manual includes - Default NOT NULL string fields to empty string on create 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("/api/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);
|
|
}
|
|
}
|