Upsert.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using MediatR;
  2. using Web.Api.Common;
  3. using Web.Api.Extensions;
  4. namespace Web.Api.Endpoints.Developers.Profile;
  5. internal sealed class Upsert : IEndpoint
  6. {
  7. public sealed record Request(
  8. string CompanyName,
  9. string BusinessNumber,
  10. string CeoName,
  11. string ContactName,
  12. string ContactPhone
  13. );
  14. public void MapEndpoint(IEndpointRouteBuilder app)
  15. {
  16. app.MapPut("api/developers/profile", async (
  17. Request body,
  18. HttpContext httpContext,
  19. ISender sender,
  20. CancellationToken ct
  21. ) => {
  22. var memberID = httpContext.User.GetRequiredMemberID();
  23. var command = new Application.Features.Api.Developers.Profile.UpsertProfile.Command(
  24. memberID,
  25. body.CompanyName,
  26. body.BusinessNumber,
  27. body.CeoName,
  28. body.ContactName,
  29. body.ContactPhone
  30. );
  31. var result = await sender.Send(command, ct);
  32. return result.Match(
  33. data => Results.Ok(data),
  34. CustomResults.Problem
  35. );
  36. })
  37. .WithTags("Developers")
  38. .RequireAuthorization();
  39. }
  40. }