2025-06-12 18:22:37 +02:00
|
|
|
|
using Vegasco.Server.Api.Persistence;
|
2024-08-23 18:02:18 +02:00
|
|
|
|
|
2025-06-12 18:22:37 +02:00
|
|
|
|
namespace Vegasco.Server.Api.Consumptions;
|
2024-08-23 18:02:18 +02:00
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|