diff --git a/barkmanAPI/Program.cs b/barkmanAPI/Program.cs index 359f9a1..cf7ed99 100644 --- a/barkmanAPI/Program.cs +++ b/barkmanAPI/Program.cs @@ -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();