Files
Projet4/PyroFetes/Endpoints/ExperienceLevel/DeleteExerienceLevelEndpoint.cs
2025-10-16 17:34:58 +02:00

30 lines
1.0 KiB
C#

using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.ExperienceLevel.Request;
using PyroFetes.DTO.ExperienceLevel.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.ExperienceLevel;
public class DeleteExerienceLevelEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetExperienceLevelDTO, GetExperienceLevelDto>
{
public override void Configure()
{
Delete ("/api/ExperienceLevels/{@Id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(GetExperienceLevelDTO req, CancellationToken ct)
{
Models.ExperienceLevel? databaseExperienceLevel = await pyroFetesDbContext.ExperienceLevels.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (databaseExperienceLevel == null)
{
await Send.NotFoundAsync(ct);
return;
}
pyroFetesDbContext.ExperienceLevels.Remove(databaseExperienceLevel);
await pyroFetesDbContext.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}