Finalisation endpoints

This commit is contained in:
2025-11-13 15:11:34 +01:00
parent 5c12a45ae6
commit 3a09bfc8ad
20 changed files with 922 additions and 0 deletions

View 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);
}
}

View File

@@ -0,0 +1,53 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Show.Request;
namespace PyroFetes.Endpoints.Show;
public class DeleteShowEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<IdShowDto>
{
public override void Configure()
{
Delete("/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
.Include(s => s.ShowTrucks)
.Include(s => s.ShowStaffs)
.Include(s => s.SoundTimecodes)
.Include(s => s.ProductTimecodes)
.Include(s => s.Contracts)
.Include(s => s.ShowMaterials)
.FirstOrDefaultAsync(s => s.Id == req.Id.Value, ct);
if (show is null)
{
await Send.NotFoundAsync(ct);
return;
}
// Supprimer les relations associées
if (show.ShowTrucks != null && show.ShowTrucks.Any())
{
pyroFetesDbContext.ShowTrucks.RemoveRange(show.ShowTrucks);
}
// Note: Les autres relations (ShowStaffs, SoundTimecodes, etc.) devront aussi être gérées
// en fonction de votre modèle de données et de vos règles métier
// Pour l'instant, je laisse juste ShowTrucks comme exemple
pyroFetesDbContext.Shows.Remove(show);
await pyroFetesDbContext.SaveChangesAsync(ct);
await Send.OkAsync(ct);
}
}

View File

@@ -0,0 +1,31 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Show.Response;
namespace PyroFetes.Endpoints.Show;
public class GetAllShowsEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<ReadShowDto>>
{
public override void Configure()
{
Get("/api/shows");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
var shows = await pyroFetesDbContext.Shows
.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
})
.ToListAsync(ct);
await Send.OkAsync(shows, ct);
}
}

View File

@@ -0,0 +1,45 @@
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
})
.FirstOrDefaultAsync(ct);
if (show is null)
{
await Send.NotFoundAsync(ct);
return;
}
await Send.OkAsync(show, ct);
}
}

View File

@@ -0,0 +1,57 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Show.Request;
using PyroFetes.DTO.Show.Response;
namespace PyroFetes.Endpoints.Show;
public class UpdateShowEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<UpdateShowDto, ReadShowDto>
{
public override void Configure()
{
Put("/api/shows/{Id}");
AllowAnonymous();
}
public override async Task HandleAsync(UpdateShowDto req, CancellationToken ct)
{
if (!req.Id.HasValue)
{
await Send.NotFoundAsync(ct);
return;
}
var show = await pyroFetesDbContext.Shows
.FirstOrDefaultAsync(s => s.Id == req.Id.Value, ct);
if (show is null)
{
await Send.NotFoundAsync(ct);
return;
}
show.Name = req.Name ?? show.Name;
show.Place = req.Place ?? show.Place;
show.Description = req.Description ?? show.Description;
show.PyrotechnicImplementationPlan = req.PyrotechnicImplementationPlan ?? show.PyrotechnicImplementationPlan;
if (req.Date.HasValue)
{
show.Date = DateOnly.FromDateTime(req.Date.Value);
}
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);
}
}