Implement all car endpoints

This commit is contained in:
2024-08-17 16:38:40 +02:00
parent a708ed25e7
commit 877e7989cd
22 changed files with 688 additions and 46 deletions

View File

@@ -0,0 +1,31 @@
using Vegasco.WebApi.Persistence;
namespace Vegasco.WebApi.Cars;
public static class DeleteCar
{
public static RouteHandlerBuilder MapEndpoint(IEndpointRouteBuilder builder)
{
return builder
.MapDelete("cars/{id:guid}", Endpoint)
.WithTags("Cars");
}
public static async Task<IResult> Endpoint(
Guid id,
ApplicationDbContext dbContext,
CancellationToken cancellationToken)
{
var car = await dbContext.Cars.FindAsync([id], cancellationToken: cancellationToken);
if (car is null)
{
return TypedResults.NotFound();
}
dbContext.Cars.Remove(car);
await dbContext.SaveChangesAsync(cancellationToken);
return TypedResults.NoContent();
}
}