Files
vegasco/src/Vegasco.Server.Api/Cars/GetCar.cs
ThompsonNye ab32be98a6
All checks were successful
continuous-integration/drone/push Build is passing
Use concrete types
2025-06-24 19:28:55 +02:00

35 lines
853 B
C#

using Microsoft.AspNetCore.Http.HttpResults;
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)
.WithDescription("Returns a single car by ID")
.WithTags("Cars")
.Produces<Response>()
.Produces(404);
}
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();
}
Response response = new Response(car.Id.Value, car.Name);
return TypedResults.Ok(response);
}
}