using TestWeb.Infra; using TestWeb.Utils; namespace TestWeb.Core.Jobs; public static class CreateJobEndpoint { public record Request( string ClientName, string Pickup, string Dropoff ); public record Response(int Id); public class RequestValidator : AbstractValidator { public RequestValidator() { RuleFor(x => x.ClientName).NotEmpty().MaximumLength(250); RuleFor(x => x.Pickup).NotEmpty().MaximumLength(120); RuleFor(x => x.Dropoff).NotEmpty().MaximumLength(120); } } public static async Task> Handle(Request request, AppDbContext db, CancellationToken ct) { var row = new Job { ClientName = request.ClientName, Pickup = request.Pickup, Dropoff = request.Dropoff, }; await db.Jobs.AddAsync(row, ct); await db.SaveChangesAsync(ct); var response = new Response(row.Id); return TypedResults.Ok(response); } }