mirror of
https://github.com/BarkProductions/barkman.git
synced 2026-06-13 06:11:55 +00:00
added rest of inventory status endpoints
This commit is contained in:
@@ -94,6 +94,52 @@ app.MapDelete("/inventory/{id}", async (int id, BarkContext db) =>
|
|||||||
app.MapGet("/itemstatus", async (BarkContext db) =>
|
app.MapGet("/itemstatus", async (BarkContext db) =>
|
||||||
await db.ItemStatus.ToListAsync());
|
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())
|
using (var serviceScope = app.Services.CreateScope())
|
||||||
{
|
{
|
||||||
var dbContext = serviceScope.ServiceProvider.GetRequiredService<BarkContext>();
|
var dbContext = serviceScope.ServiceProvider.GetRequiredService<BarkContext>();
|
||||||
|
|||||||
Reference in New Issue
Block a user