some changes

This commit is contained in:
2025-01-08 10:55:59 -06:00
parent b05abfba0e
commit 0bc0c9e76f
2 changed files with 20 additions and 6 deletions
+16 -6
View File
@@ -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<InventoryContext>().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();