| 1234567891011121314151617181920212223242526272829303132 |
- using MediatR;
- using Web.Api.Common;
- using Web.Api.Extensions;
- namespace Web.Api.Endpoints.Developers.Tokens;
- internal sealed class Issue : IEndpoint
- {
- public sealed record Request(string Name, List<string>? Scopes, DateTime? ExpiresAt);
- public void MapEndpoint(IEndpointRouteBuilder app)
- {
- app.MapPost("api/developers/tokens", async (
- Request body,
- HttpContext httpContext,
- ISender sender,
- CancellationToken ct
- ) => {
- var memberID = httpContext.User.GetRequiredMemberID();
- var command = new Application.Features.Api.Developers.Tokens.IssuePat.Command(
- memberID, body.Name, body.Scopes ?? [], body.ExpiresAt
- );
- var result = await sender.Send(command, ct);
- return result.Match(
- data => Results.Ok(data),
- CustomResults.Problem
- );
- })
- .WithTags("Developers")
- .RequireAuthorization();
- }
- }
|