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>
47 lines
1.3 KiB
C#
47 lines
1.3 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("/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,
|
|
CityId = s.CityId
|
|
})
|
|
.FirstOrDefaultAsync(ct);
|
|
|
|
if (show is null)
|
|
{
|
|
await Send.NotFoundAsync(ct);
|
|
return;
|
|
}
|
|
|
|
await Send.OkAsync(show, ct);
|
|
}
|
|
}
|