Files
vegasco/src/Vegasco.Server.Api/Consumptions/DeleteConsumptions.cs
ThompsonNye a1999bfe41
All checks were successful
continuous-integration/drone/push Build is passing
Rename WebApi project to Vegasco.Server.Api
And update all references including comments etc.
2025-06-12 18:23:09 +02:00

30 lines
766 B
C#

using Vegasco.Server.Api.Persistence;
namespace Vegasco.Server.Api.Consumptions;
public static class DeleteConsumption
{
public static RouteHandlerBuilder MapEndpoint(IEndpointRouteBuilder builder)
{
return builder
.MapDelete("consumptions/{id:guid}", Endpoint)
.WithTags("Consumptions");
}
private static async Task<IResult> Endpoint(
ApplicationDbContext dbContext,
Guid id,
CancellationToken cancellationToken)
{
Consumption? consumption = await dbContext.Consumptions.FindAsync([new ConsumptionId(id)], cancellationToken);
if (consumption is null)
{
return TypedResults.NotFound();
}
dbContext.Consumptions.Remove(consumption);
await dbContext.SaveChangesAsync(cancellationToken);
return TypedResults.NoContent();
}
}