Create.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using MediatR;
  2. using Web.Api.Common;
  3. using Web.Api.Extensions;
  4. namespace Web.Api.Endpoints.Developers.Apps;
  5. internal sealed class Create : IEndpoint
  6. {
  7. public sealed record Request(string Name, string? Description, string? HomepageUrl, List<string>? Scopes);
  8. public void MapEndpoint(IEndpointRouteBuilder app)
  9. {
  10. app.MapPost("api/developers/apps", 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.Apps.CreateApp.Command(
  18. memberID,
  19. body.Name,
  20. body.Description,
  21. body.HomepageUrl,
  22. body.Scopes ?? []
  23. );
  24. var result = await sender.Send(command, ct);
  25. return result.Match(
  26. data => ApiResponse.Ok(data),
  27. CustomResults.Problem
  28. );
  29. })
  30. .WithTags("Developers")
  31. .RequireAuthorization();
  32. }
  33. }