InventoryEndpoints.cs 1.1 KB

123456789101112131415161718192021222324252627
  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.MapGet("/health", () => Results.Content("rackpeek", "text/plain"))
  7. .DisableAntiforgery();
  8. app.MapPost("/api/inventory",
  9. async (ImportYamlRequest request,
  10. UpsertInventoryUseCase useCase) => {
  11. try {
  12. ImportYamlResponse result = await useCase.ExecuteAsync(request);
  13. return Results.Ok(result);
  14. }
  15. catch (ValidationException ex) {
  16. return Results.BadRequest(new { error = ex.Message });
  17. }
  18. catch (Exception ex) {
  19. return Results.BadRequest(new { error = $"Import failed: {ex.Message}" });
  20. }
  21. })
  22. .AddEndpointFilter<ApiKeyEndpointFilter>()
  23. .DisableAntiforgery();
  24. }
  25. }