From 0bc0c9e76fabee27f32622a5a7a5381b1886fc8b Mon Sep 17 00:00:00 2001 From: Drew Rautenberg Date: Wed, 8 Jan 2025 10:55:59 -0600 Subject: [PATCH] some changes --- barkmanAPI/Program.cs | 22 ++++++++++++++++------ barkmanAPI/barkmanAPI.csproj | 4 ++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/barkmanAPI/Program.cs b/barkmanAPI/Program.cs index 304aebc..408d7d3 100644 --- a/barkmanAPI/Program.cs +++ b/barkmanAPI/Program.cs @@ -1,5 +1,5 @@ +using Microsoft.EntityFrameworkCore; using Microsoft.OpenApi.Models; -using BarkMan.DB; var builder = WebApplication.CreateBuilder(args); @@ -23,10 +23,20 @@ if (app.Environment.IsDevelopment()) app.MapGet("/", () => "Hello World!"); -app.MapGet("/inventory/{id}", (int id) => InventoryDb.GetInventory(id)); -app.MapGet("/inventory", () => InventoryDb.GetInventory()); -app.MapPost("/inventory", (InventoryItem item) => InventoryDb.CreateInventoryItem(item)); -app.MapPut("/inventory", (InventoryItem item) => InventoryDb.UpdateItem(item)); -app.MapDelete("/inventory/{id}", (int id) => InventoryDb.RemoveItem(id)); +app.MapGet("/inventory", async (InventoryContext dbContext) => +{ + var inventoryItems = await dbContext.Set().ToListAsync(); + return Results.Ok(inventoryItems); +}); + +app.MapPost("/inventory", async (InventoryContext dbContext, InventoryContext newItem) => +{ + dbContext.Add(newItem); + await dbContext.SaveChangesAsync(); + return Results.Created($"/inventory/{newItem.Id}", newItem); +}); +//app.MapGet("/inventory/{id}", (int id) => InventoryDb.GetInventory(id)); +//app.MapPut("/inventory", (InventoryItem item) => InventoryDb.UpdateItem(item)); +//app.MapDelete("/inventory/{id}", (int id) => InventoryDb.RemoveItem(id)); app.Run(); \ No newline at end of file diff --git a/barkmanAPI/barkmanAPI.csproj b/barkmanAPI/barkmanAPI.csproj index ccbffe7..8af45f7 100644 --- a/barkmanAPI/barkmanAPI.csproj +++ b/barkmanAPI/barkmanAPI.csproj @@ -9,6 +9,10 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all +