added rest of inventory status endpoints

This commit is contained in:
2025-01-23 13:24:16 -06:00
parent 58e19bd32a
commit b13acf36ed
+46
View File
@@ -94,6 +94,52 @@ app.MapDelete("/inventory/{id}", async (int id, BarkContext db) =>
app.MapGet("/itemstatus", async (BarkContext db) =>
await db.ItemStatus.ToListAsync());
app.MapPost("/itemstatus", async (ItemStatus newItemStatus, BarkContext db) =>
{
db.ItemStatus.Add(newItemStatus);
await db.SaveChangesAsync();
return Results.Created($"/itemstatus/{newItemStatus.Id}", newItemStatus);
});
app.MapGet("/itemstatus/{id}", async (string id, BarkContext db) =>
{
var itemStatus = await db.ItemStatus.FindAsync(id);
if (itemStatus == null)
{
return Results.NotFound(new { Message = "Item Status not found" });
}
return Results.Ok(itemStatus);
});
app.MapPut("/itemstatus/{id}", async (string id, ItemStatus updatedStatus, BarkContext db) =>
{
var existingStatus = await db.ItemStatus.FindAsync(id);
if (existingStatus == null)
{
return Results.NotFound(new { Message = "Inventory item not found" });
}
existingStatus.Id = updatedStatus.Id;
existingStatus.Name = updatedStatus.Name;
await db.SaveChangesAsync();
return Results.Ok(existingStatus);
});
app.MapDelete("/itemstatus/{id}", async (string id, BarkContext db) =>
{
var itemStatus = await db.ItemStatus.FindAsync(id);
if (itemStatus == null)
{
return Results.NotFound(new { Message = "Item status not found" });
}
db.ItemStatus.Remove(itemStatus);
await db.SaveChangesAsync();
return Results.Ok(new { Message = "Item status deleted successfully" });
});
using (var serviceScope = app.Services.CreateScope())
{
var dbContext = serviceScope.ServiceProvider.GetRequiredService<BarkContext>();