Issue.cs 1011 B

1234567891011121314151617181920212223242526272829303132
  1. using MediatR;
  2. using Web.Api.Common;
  3. using Web.Api.Extensions;
  4. namespace Web.Api.Endpoints.Developers.Tokens;
  5. internal sealed class Issue : IEndpoint
  6. {
  7. public sealed record Request(string Name, List<string>? Scopes, DateTime? ExpiresAt);
  8. public void MapEndpoint(IEndpointRouteBuilder app)
  9. {
  10. app.MapPost("api/developers/tokens", async (
  11. Request body,
  12. HttpContext httpContext,
  13. ISender sender,
  14. CancellationToken ct
  15. ) => {
  16. var memberID = httpContext.User.GetRequiredMemberID();
  17. var command = new Application.Features.Api.Developers.Tokens.IssuePat.Command(
  18. memberID, body.Name, body.Scopes ?? [], body.ExpiresAt
  19. );
  20. var result = await sender.Send(command, ct);
  21. return result.Match(
  22. data => Results.Ok(data),
  23. CustomResults.Problem
  24. );
  25. })
  26. .WithTags("Developers")
  27. .RequireAuthorization();
  28. }
  29. }