added job itms endpoints

This commit is contained in:
2026-07-19 20:50:02 -05:00
parent 656ccd7d52
commit 0d2e049e69
+46
View File
@@ -346,6 +346,52 @@ jobStatusGroup.MapDelete("/{id}", async (string id, BarkContext db) =>
return Results.Ok(new { Message = "Job status deleted successfully" }); return Results.Ok(new { Message = "Job status deleted successfully" });
}); });
jobItemGroup.MapGet("", async (BarkContext db) =>
await db.JobItems.OrderBy(items => items.Id).ToListAsync());
jobItemGroup.MapGet("/{id}", async (int id, BarkContext db) =>
{
var jobItems = await db.JobItems
.FirstOrDefaultAsync(i => i.Id == id);
if (jobItems == null)
{
return Results.NotFound(new { Message = "Job Items not found" });
}
return Results.Ok(jobItems);
});
jobItemGroup.MapPut("/{id}", async (int id, JobItems updatedJobItems, BarkContext db) =>
{
var existingJobItems = await db.JobItems.FindAsync(id);
if (existingJobItems == null)
{
return Results.NotFound(new { Message = "Job Items not found" });
}
existingJobItems.OrderId = updatedJobItems.OrderId;
existingJobItems.ItemId = updatedJobItems.ItemId;
existingJobItems.Quantity = updatedJobItems.Quantity;
await db.SaveChangesAsync();
return Results.Ok(existingJobItems);
});
jobItemGroup.MapPost("", async (JobItems newJobItemsInput, BarkContext db) =>
{
var newJobItem = new JobItems()
{
OrderId = newJobItemsInput.OrderId,
ItemId = newJobItemsInput.ItemId,
Quantity = newJobItemsInput.Quantity,
};
db.JobItems.Add(newJobItem);
await db.SaveChangesAsync();
return Results.Created($"/jobItems/{newJobItem.Id}", newJobItem);
});
using (var serviceScope = app.Services.CreateScope()) using (var serviceScope = app.Services.CreateScope())
{ {
var dbContext = serviceScope.ServiceProvider.GetRequiredService<BarkContext>(); var dbContext = serviceScope.ServiceProvider.GetRequiredService<BarkContext>();