added job endpoints

This commit is contained in:
2026-07-19 16:10:09 -05:00
parent 8b0a90d2e5
commit 7dcc366393
+62
View File
@@ -51,6 +51,14 @@ var customerGroup = app.MapGroup(prefix: "/customers")
.WithTags("Customers") .WithTags("Customers")
.WithDescription("Endpoints for managing customers"); .WithDescription("Endpoints for managing customers");
var jobGroup = app.MapGroup(prefix: "/jobs")
.WithTags("Jobs")
.WithDescription("Endpoints for managing jobs");
var jobItemGroup = app.MapGroup(prefix: "/jobitems")
.WithTags("Job Items")
.WithDescription("Endpoints for managing job items");
inventoryGroup.MapGet("", async (BarkContext db) => inventoryGroup.MapGet("", async (BarkContext db) =>
await db.Inventory.OrderBy(item => item.Barcode).ToListAsync()); await db.Inventory.OrderBy(item => item.Barcode).ToListAsync());
@@ -232,6 +240,60 @@ customerGroup.MapDelete("/{id}", async (int id, BarkContext db) =>
return Results.Ok(new { Message = "Customer deleted successfully" }); return Results.Ok(new { Message = "Customer deleted successfully" });
}); });
jobGroup.MapGet("", async (BarkContext db) =>
await db.Jobs.OrderBy(jobs => jobs.Id).ToListAsync());
jobGroup.MapGet("/{id}", async (int id, BarkContext db) =>
{
var job = await db.Jobs
.FirstOrDefaultAsync(i => i.Id == id);
if (job == null)
{
return Results.NotFound(new { Message = "Job not found" });
}
return Results.Ok(job);
});
jobGroup.MapPut("/{id}", async (int id, Jobs ubdatedJob, BarkContext db) =>
{
var existingJob = await db.Jobs.FindAsync(id);
if (existingJob == null)
{
return Results.NotFound(new { Message = "Customer not found" });
}
existingJob.Name = ubdatedJob.Name;
existingJob.StartDate = ubdatedJob.StartDate;
existingJob.EndDate = ubdatedJob.EndDate;
existingJob.TotalPrice = ubdatedJob.TotalPrice;
existingJob.Venue = ubdatedJob.Venue;
existingJob.Address = ubdatedJob.Address;
existingJob.Notes = ubdatedJob.Notes;
await db.SaveChangesAsync();
return Results.Ok(existingJob);
});
jobGroup.MapPost("", async (Jobs newJobInput, BarkContext db) =>
{
var newJob = new Jobs()
{
CustomerId = newJobInput.CustomerId,
Name = newJobInput.Name,
StartDate = newJobInput.StartDate,
EndDate = newJobInput.EndDate,
Venue = newJobInput.Venue,
Address = newJobInput.Address,
};
db.Jobs.Add(newJob);
await db.SaveChangesAsync();
return Results.Created($"/jobs/{newJob.Id}", newJob);
});
using (var serviceScope = app.Services.CreateScope()) using (var serviceScope = app.Services.CreateScope())
{ {
var dbContext = serviceScope.ServiceProvider.GetRequiredService<BarkContext>(); var dbContext = serviceScope.ServiceProvider.GetRequiredService<BarkContext>();