Endopoint presque fini
This commit is contained in:
29
PF3/Endpoints/SoundCategory/DeleteSoundCategoryEndpoint.cs
Normal file
29
PF3/Endpoints/SoundCategory/DeleteSoundCategoryEndpoint.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PF3.DTO.SoundCategory.Request;
|
||||
|
||||
namespace PF3.Endpoints.SoundCategory;
|
||||
|
||||
public class DeleteSoundCategoryEndpoint(PF3DbContext 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.SoundsCategorys.FirstOrDefaultAsync(st => st.Id == req.Id, ct);
|
||||
if (soundCategory is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
pf3DbContext.SoundsCategorys.Remove(soundCategory);
|
||||
await pf3DbContext.SaveChangesAsync(ct);
|
||||
|
||||
await Send.OkAsync(ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user