mirror of
https://github.com/BarkProductions/barkman.git
synced 2026-06-13 06:11:55 +00:00
things
This commit is contained in:
+14
-11
@@ -47,12 +47,15 @@ var itemStatusGroup = app.MapGroup(prefix: "/itemstatus")
|
||||
.WithTags("Item Status")
|
||||
.WithDescription("Endpoints for managing item status");
|
||||
|
||||
inventoryGroup.MapGet("/inventory", async (BarkContext db) =>
|
||||
inventoryGroup.MapGet("", async (BarkContext db) =>
|
||||
await db.Inventory.OrderBy(item => item.Id).ToListAsync());
|
||||
|
||||
inventoryGroup.MapGet("/inventory/{id}", async (int id, BarkContext db) =>
|
||||
inventoryGroup.MapGet("/{id}", async (int id, BarkContext db) =>
|
||||
{
|
||||
var item = await db.Inventory.FindAsync(id);
|
||||
var item = await db.Inventory
|
||||
.Include(item => item.StatusId)
|
||||
.FirstOrDefaultAsync(i => i.Id == id);
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
return Results.NotFound(new { Message = "Inventory item not found" });
|
||||
@@ -61,7 +64,7 @@ inventoryGroup.MapGet("/inventory/{id}", async (int id, BarkContext db) =>
|
||||
return Results.Ok(item);
|
||||
});
|
||||
|
||||
inventoryGroup.MapPut("/inventory/{id}", async (int id, InventoryItems updatedItem, BarkContext db) =>
|
||||
inventoryGroup.MapPut("/{id}", async (int id, InventoryItems updatedItem, BarkContext db) =>
|
||||
{
|
||||
var existingItem = await db.Inventory.FindAsync(id);
|
||||
if (existingItem == null)
|
||||
@@ -82,14 +85,14 @@ inventoryGroup.MapPut("/inventory/{id}", async (int id, InventoryItems updatedIt
|
||||
});
|
||||
|
||||
|
||||
inventoryGroup.MapPost("/inventory", async (InventoryItems newItem, BarkContext db) =>
|
||||
inventoryGroup.MapPost("", async (InventoryItems newItem, BarkContext db) =>
|
||||
{
|
||||
db.Inventory.Add(newItem);
|
||||
await db.SaveChangesAsync();
|
||||
return Results.Created($"/inventory/{newItem.Id}", newItem);
|
||||
});
|
||||
|
||||
inventoryGroup.MapDelete("/inventory/{id}", async (int id, BarkContext db) =>
|
||||
inventoryGroup.MapDelete("/{id}", async (int id, BarkContext db) =>
|
||||
{
|
||||
var item = await db.Inventory.FindAsync(id);
|
||||
if (item == null)
|
||||
@@ -102,17 +105,17 @@ inventoryGroup.MapDelete("/inventory/{id}", async (int id, BarkContext db) =>
|
||||
return Results.Ok(new { Message = "Inventory item deleted successfully" });
|
||||
});
|
||||
|
||||
itemStatusGroup.MapGet("/itemstatus", async (BarkContext db) =>
|
||||
itemStatusGroup.MapGet("/", async (BarkContext db) =>
|
||||
await db.ItemStatus.ToListAsync());
|
||||
|
||||
itemStatusGroup.MapPost("/itemstatus", async (ItemStatus newItemStatus, BarkContext db) =>
|
||||
itemStatusGroup.MapPost("/", async (ItemStatus newItemStatus, BarkContext db) =>
|
||||
{
|
||||
db.ItemStatus.Add(newItemStatus);
|
||||
await db.SaveChangesAsync();
|
||||
return Results.Created($"/itemstatus/{newItemStatus.Id}", newItemStatus);
|
||||
});
|
||||
|
||||
itemStatusGroup.MapGet("/itemstatus/{id}", async (string id, BarkContext db) =>
|
||||
itemStatusGroup.MapGet("/{id}", async (string id, BarkContext db) =>
|
||||
{
|
||||
var itemStatus = await db.ItemStatus.FindAsync(id);
|
||||
if (itemStatus == null)
|
||||
@@ -123,7 +126,7 @@ itemStatusGroup.MapGet("/itemstatus/{id}", async (string id, BarkContext db) =>
|
||||
return Results.Ok(itemStatus);
|
||||
});
|
||||
|
||||
itemStatusGroup.MapPut("/itemstatus/{id}", async (string id, ItemStatus updatedStatus, BarkContext db) =>
|
||||
itemStatusGroup.MapPut("/{id}", async (string id, ItemStatus updatedStatus, BarkContext db) =>
|
||||
{
|
||||
var existingStatus = await db.ItemStatus.FindAsync(id);
|
||||
if (existingStatus == null)
|
||||
@@ -138,7 +141,7 @@ itemStatusGroup.MapPut("/itemstatus/{id}", async (string id, ItemStatus updatedS
|
||||
return Results.Ok(existingStatus);
|
||||
});
|
||||
|
||||
itemStatusGroup.MapDelete("/itemstatus/{id}", async (string id, BarkContext db) =>
|
||||
itemStatusGroup.MapDelete("/{id}", async (string id, BarkContext db) =>
|
||||
{
|
||||
var itemStatus = await db.ItemStatus.FindAsync(id);
|
||||
if (itemStatus == null)
|
||||
|
||||
Reference in New Issue
Block a user