From 7dcc366393a55d1d624b688689272954cba6d6f8 Mon Sep 17 00:00:00 2001 From: Drew Rautenberg Date: Sun, 19 Jul 2026 16:10:09 -0500 Subject: [PATCH] added job endpoints --- barkmanAPI/Program.cs | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/barkmanAPI/Program.cs b/barkmanAPI/Program.cs index 9a9de8e..697d9f0 100644 --- a/barkmanAPI/Program.cs +++ b/barkmanAPI/Program.cs @@ -51,6 +51,14 @@ var customerGroup = app.MapGroup(prefix: "/customers") .WithTags("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) => 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" }); }); +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()) { var dbContext = serviceScope.ServiceProvider.GetRequiredService();