From 656ccd7d52d26d35e1d9fba829d1af093d6dc7f3 Mon Sep 17 00:00:00 2001 From: Drew Rautenberg Date: Sun, 19 Jul 2026 20:41:02 -0500 Subject: [PATCH] added endpoints and fixed some typos --- barkmanAPI/Program.cs | 72 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 10 deletions(-) diff --git a/barkmanAPI/Program.cs b/barkmanAPI/Program.cs index 697d9f0..f137c77 100644 --- a/barkmanAPI/Program.cs +++ b/barkmanAPI/Program.cs @@ -55,6 +55,10 @@ var jobGroup = app.MapGroup(prefix: "/jobs") .WithTags("Jobs") .WithDescription("Endpoints for managing jobs"); +var jobStatusGroup = app.MapGroup(prefix: "/jobstatus") + .WithTags("Job Status") + .WithDescription("Endpoints for managing job status"); + var jobItemGroup = app.MapGroup(prefix: "/jobitems") .WithTags("Job Items") .WithDescription("Endpoints for managing job items"); @@ -152,7 +156,7 @@ itemStatusGroup.MapPut("/{id}", async (string id, ItemStatus updatedStatus, Bark var existingStatus = await db.ItemStatus.FindAsync(id); if (existingStatus == null) { - return Results.NotFound(new { Message = "Inventory item not found" }); + return Results.NotFound(new { Message = "Item status not found" }); } existingStatus.Id = updatedStatus.Id; @@ -256,21 +260,21 @@ jobGroup.MapGet("/{id}", async (int id, BarkContext db) => return Results.Ok(job); }); -jobGroup.MapPut("/{id}", async (int id, Jobs ubdatedJob, BarkContext db) => +jobGroup.MapPut("/{id}", async (int id, Jobs updatedJob, BarkContext db) => { var existingJob = await db.Jobs.FindAsync(id); if (existingJob == null) { - return Results.NotFound(new { Message = "Customer not found" }); + return Results.NotFound(new { Message = "Job 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; + existingJob.Name = updatedJob.Name; + existingJob.StartDate = updatedJob.StartDate; + existingJob.EndDate = updatedJob.EndDate; + existingJob.TotalPrice = updatedJob.TotalPrice; + existingJob.Venue = updatedJob.Venue; + existingJob.Address = updatedJob.Address; + existingJob.Notes = updatedJob.Notes; await db.SaveChangesAsync(); return Results.Ok(existingJob); @@ -293,6 +297,54 @@ jobGroup.MapPost("", async (Jobs newJobInput, BarkContext db) => return Results.Created($"/jobs/{newJob.Id}", newJob); }); +jobStatusGroup.MapGet("/", async (BarkContext db) => + await db.JobStatus.ToListAsync()); + +jobStatusGroup.MapPost("/", async (JobStatus newJobStatus, BarkContext db) => +{ + db.JobStatus.Add(newJobStatus); + await db.SaveChangesAsync(); + return Results.Created($"/jobstatus/{newJobStatus.Id}", newJobStatus); +}); + +jobStatusGroup.MapGet("/{id}", async (string id, BarkContext db) => +{ + var jobStatus = await db.JobStatus.FindAsync(id); + if (jobStatus == null) + { + return Results.NotFound(new { Message = "Job Status not found" }); + } + + return Results.Ok(jobStatus); +}); + +jobStatusGroup.MapPut("/{id}", async (string id, JobStatus updatedStatus, BarkContext db) => +{ + var existingStatus = await db.JobStatus.FindAsync(id); + if (existingStatus == null) + { + return Results.NotFound(new { Message = "Job status not found" }); + } + + existingStatus.Id = updatedStatus.Id; + existingStatus.Name = updatedStatus.Name; + + await db.SaveChangesAsync(); + return Results.Ok(existingStatus); +}); + +jobStatusGroup.MapDelete("/{id}", async (string id, BarkContext db) => +{ + var jobStatus = await db.JobStatus.FindAsync(id); + if (jobStatus == null) + { + return Results.NotFound(new { Message = "Job status not found" }); + } + + db.JobStatus.Remove(jobStatus); + await db.SaveChangesAsync(); + return Results.Ok(new { Message = "Job status deleted successfully" }); +}); using (var serviceScope = app.Services.CreateScope()) {