mirror of
https://github.com/BarkProductions/barkman.git
synced 2026-06-12 22:11:54 +00:00
things
This commit is contained in:
+14
-11
@@ -47,12 +47,15 @@ var itemStatusGroup = app.MapGroup(prefix: "/itemstatus")
|
|||||||
.WithTags("Item Status")
|
.WithTags("Item Status")
|
||||||
.WithDescription("Endpoints for managing 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());
|
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)
|
if (item == null)
|
||||||
{
|
{
|
||||||
return Results.NotFound(new { Message = "Inventory item not found" });
|
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);
|
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);
|
var existingItem = await db.Inventory.FindAsync(id);
|
||||||
if (existingItem == null)
|
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);
|
db.Inventory.Add(newItem);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
return Results.Created($"/inventory/{newItem.Id}", newItem);
|
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);
|
var item = await db.Inventory.FindAsync(id);
|
||||||
if (item == null)
|
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" });
|
return Results.Ok(new { Message = "Inventory item deleted successfully" });
|
||||||
});
|
});
|
||||||
|
|
||||||
itemStatusGroup.MapGet("/itemstatus", async (BarkContext db) =>
|
itemStatusGroup.MapGet("/", async (BarkContext db) =>
|
||||||
await db.ItemStatus.ToListAsync());
|
await db.ItemStatus.ToListAsync());
|
||||||
|
|
||||||
itemStatusGroup.MapPost("/itemstatus", async (ItemStatus newItemStatus, BarkContext db) =>
|
itemStatusGroup.MapPost("/", async (ItemStatus newItemStatus, BarkContext db) =>
|
||||||
{
|
{
|
||||||
db.ItemStatus.Add(newItemStatus);
|
db.ItemStatus.Add(newItemStatus);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
return Results.Created($"/itemstatus/{newItemStatus.Id}", newItemStatus);
|
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);
|
var itemStatus = await db.ItemStatus.FindAsync(id);
|
||||||
if (itemStatus == null)
|
if (itemStatus == null)
|
||||||
@@ -123,7 +126,7 @@ itemStatusGroup.MapGet("/itemstatus/{id}", async (string id, BarkContext db) =>
|
|||||||
return Results.Ok(itemStatus);
|
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);
|
var existingStatus = await db.ItemStatus.FindAsync(id);
|
||||||
if (existingStatus == null)
|
if (existingStatus == null)
|
||||||
@@ -138,7 +141,7 @@ itemStatusGroup.MapPut("/itemstatus/{id}", async (string id, ItemStatus updatedS
|
|||||||
return Results.Ok(existingStatus);
|
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);
|
var itemStatus = await db.ItemStatus.FindAsync(id);
|
||||||
if (itemStatus == null)
|
if (itemStatus == null)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class InventoryItems
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string Brand { get; set; }
|
public string Brand { get; set; }
|
||||||
public string? SerialNumber { get; set; }
|
public string? SerialNumber { get; set; }
|
||||||
public string? StatusId { get; set; }
|
public ItemStatus StatusId { get; set; }
|
||||||
public float? RentalPrice { get; set; }
|
public float? RentalPrice { get; set; }
|
||||||
public float? ReplacementCost { get; set; }
|
public float? ReplacementCost { get; set; }
|
||||||
public string? Notes { get; set; }
|
public string? Notes { get; set; }
|
||||||
|
|||||||
Reference in New Issue
Block a user