Register.cs 927 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using MediatR;
  2. using Web.Api.Extensions;
  3. using Web.Api.Common;
  4. namespace Web.Api.Endpoints.Auth;
  5. internal sealed class Register : IEndpoint
  6. {
  7. public sealed record Request(
  8. string Email,
  9. string Password,
  10. string? Name
  11. );
  12. public void MapEndpoint(IEndpointRouteBuilder app)
  13. {
  14. app.MapPost("api/auth/register", async (
  15. Request request,
  16. ISender sender,
  17. CancellationToken ct
  18. ) => {
  19. var command = new Application.Features.Api.Auth.Register.Command(
  20. request.Email,
  21. request.Password,
  22. request.Name
  23. );
  24. var result = await sender.Send(command, ct);
  25. return result.Match(
  26. id => ApiResponse.Created(new { id }),
  27. CustomResults.Problem
  28. );
  29. })
  30. .WithTags("Auth")
  31. .AllowAnonymous();
  32. }
  33. }