Finalisation endpoints
This commit is contained in:
41
PyroFetes/Endpoints/Show/CreateShowEndpoint.cs
Normal file
41
PyroFetes/Endpoints/Show/CreateShowEndpoint.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
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,
|
||||
Place = req.Place,
|
||||
Description = req.Description,
|
||||
PyrotechnicImplementationPlan = req.PyrotechnicImplementationPlan,
|
||||
Date = req.Date.HasValue ? DateOnly.FromDateTime(req.Date.Value) : null
|
||||
};
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
await Send.OkAsync(result, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user