4
0

InventoryEndpoints.cs 1021 B

12345678910111213141516171819202122232425
  1. using System.ComponentModel.DataAnnotations;
  2. using RackPeek.Domain.Api;
  3. namespace RackPeek.Web.Api;
  4. public static class InventoryEndpoints {
  5. public static void MapInventoryApi(this WebApplication app) {
  6. app.MapPost("/api/inventory",
  7. async (ImportYamlRequest request,
  8. UpsertInventoryUseCase useCase) => {
  9. try {
  10. ImportYamlResponse result = await useCase.ExecuteAsync(request);
  11. return Results.Ok(result);
  12. }
  13. catch (ValidationException ex) {
  14. return Results.BadRequest(new { error = ex.Message });
  15. }
  16. catch (Exception ex) {
  17. return Results.BadRequest(new { error = $"Import failed: {ex.Message}" });
  18. }
  19. })
  20. .AddEndpointFilter<ApiKeyEndpointFilter>()
  21. .DisableAntiforgery();
  22. }
  23. }