Watch
1
0
Fork
You've already forked test-web
0
test-web/src/Core/Jobs/CreateJobEndpoint.cs
Chris Dill 0e79a8eb5e
All checks were successful
Build / build (push) Successful in 52s
Initial commit
2026-05-30 12:26:50 +01:00

41 lines
1 KiB
C#

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<Request>
{
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<Ok<Response>> 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);
}
}