Register.cs 952 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. // ȸ¿ø°¡ÀÔ ¿äû
  15. app.MapPost("api/auth/register", async (
  16. Request request,
  17. ISender sender,
  18. CancellationToken ct
  19. ) => {
  20. var command = new Application.Features.Api.Auth.Register.Command(
  21. request.Email,
  22. request.Password,
  23. request.Name
  24. );
  25. var result = await sender.Send(command, ct);
  26. return result.Match(
  27. result => ApiResponse.Created(result),
  28. CustomResults.Problem
  29. );
  30. })
  31. .WithTags("Auth")
  32. .AllowAnonymous();
  33. }
  34. }