Files
PF3-fork/PyroFetes/Endpoints/SoundCategory/DeleteSoundCategoryEndpoint.cs
2025-11-13 15:11:12 +01:00

29 lines
851 B
C#

using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.SoundCategory.Request;
namespace PyroFetes.Endpoints.SoundCategory;
public class DeleteSoundCategoryEndpoint(PyroFetesDbContext pf3DbContext) : Endpoint<IdSoundCategoryDto>
{
public override void Configure()
{
Delete("/api/soundcategorys/{Id}");
AllowAnonymous();
}
public override async Task HandleAsync(IdSoundCategoryDto req, CancellationToken ct)
{
var soundCategory = await pf3DbContext.SoundCategories.FirstOrDefaultAsync(st => st.Id == req.Id, ct);
if (soundCategory is null)
{
await Send.NotFoundAsync(ct);
return;
}
pf3DbContext.SoundCategories.Remove(soundCategory);
await pf3DbContext.SaveChangesAsync(ct);
await Send.OkAsync(ct);
}
}