2024-08-17 16:38:40 +02:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
using Vegasco.WebApi.Persistence;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Vegasco.WebApi.Cars;
|
|
|
|
|
|
|
|
|
|
|
|
public static class GetCars
|
|
|
|
|
|
{
|
|
|
|
|
|
public record Response(Guid Id, string Name);
|
|
|
|
|
|
|
|
|
|
|
|
public static RouteHandlerBuilder MapEndpoint(IEndpointRouteBuilder builder)
|
|
|
|
|
|
{
|
|
|
|
|
|
return builder
|
|
|
|
|
|
.MapGet("cars", Endpoint)
|
|
|
|
|
|
.WithTags("Cars");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-17 16:38:40 +02:00
|
|
|
|
private static async Task<IResult> Endpoint(
|
2024-08-17 16:38:40 +02:00
|
|
|
|
ApplicationDbContext dbContext,
|
|
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
|
{
|
|
|
|
|
|
var cars = await dbContext.Cars
|
|
|
|
|
|
.Select(x => new Response(x.Id, x.Name))
|
|
|
|
|
|
.ToListAsync(cancellationToken);
|
|
|
|
|
|
|
|
|
|
|
|
return TypedResults.Ok(cars);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|