mirror of
https://github.com/BarkProductions/barkman.git
synced 2026-08-11 11:42:03 +00:00
added job itms endpoints
This commit is contained in:
@@ -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>();
|
||||||
|
|||||||
Reference in New Issue
Block a user