Update.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. using MediatR;
  2. using Web.Api.Common;
  3. using Web.Api.Extensions;
  4. namespace Web.Api.Endpoints.Developers.Apps;
  5. internal sealed class Update : IEndpoint
  6. {
  7. public sealed record Request(string Name, string? Description, string? HomepageUrl);
  8. public void MapEndpoint(IEndpointRouteBuilder app)
  9. {
  10. app.MapPut("api/developers/apps/{appID:int}", async (
  11. int appID,
  12. Request body,
  13. HttpContext httpContext,
  14. ISender sender,
  15. CancellationToken ct
  16. ) => {
  17. var memberID = httpContext.User.GetRequiredMemberID();
  18. var command = new Application.Features.Api.Developers.Apps.UpdateApp.Command(
  19. memberID, appID, body.Name, body.Description, body.HomepageUrl
  20. );
  21. var result = await sender.Send(command, ct);
  22. return result.Match(
  23. () => Results.NoContent(),
  24. CustomResults.Problem
  25. );
  26. })
  27. .WithTags("Developers")
  28. .RequireAuthorization();
  29. }
  30. }