All checks were successful
continuous-integration/drone/push Build is passing
And update all references including comments etc.
32 lines
711 B
C#
32 lines
711 B
C#
using Vegasco.Server.Api.Persistence;
|
|
|
|
namespace Vegasco.Server.Api.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");
|
|
}
|
|
|
|
private static async Task<IResult> Endpoint(
|
|
Guid id,
|
|
ApplicationDbContext dbContext,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
Car? car = await dbContext.Cars.FindAsync([new CarId(id)], cancellationToken: cancellationToken);
|
|
|
|
if (car is null)
|
|
{
|
|
return TypedResults.NotFound();
|
|
}
|
|
|
|
var response = new Response(car.Id.Value, car.Name);
|
|
return TypedResults.Ok(response);
|
|
}
|
|
}
|