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

31
src/WebApi/Cars/GetCar.cs Normal file
View File

@@ -0,0 +1,31 @@
using Vegasco.WebApi.Persistence;
namespace Vegasco.WebApi.Cars;
public static class GetCar
{
public record Response(Guid Id, string Name);
public static RouteHandlerBuilder MapEndpoint(IEndpointRouteBuilder builder)
{
return builder
.MapGet("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();
}
var response = new Response(car.Id, car.Name);
return TypedResults.Ok(response);
}
}