feat: add delete functionality for exercises and routines
This commit is contained in:
@@ -79,6 +79,23 @@ internal static class ExerciseEndpoints
|
||||
.WithSummary("Update exercise")
|
||||
.WithDescription("Updates the name of an exercise for the specified user.");
|
||||
|
||||
group.MapDelete("/users/{userId}/exercises/{exerciseId:int}", async (string userId, int exerciseId, AppDbContext db) =>
|
||||
{
|
||||
var user = await UserProvisioning.EnsureUserAsync(db, userId);
|
||||
var exercise = await db.Exercises.FirstOrDefaultAsync(e => e.Id == exerciseId && e.UserId == user.Id);
|
||||
if (exercise is null)
|
||||
{
|
||||
return Results.NotFound();
|
||||
}
|
||||
|
||||
db.Exercises.Remove(exercise);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return Results.NoContent();
|
||||
})
|
||||
.WithSummary("Delete exercise")
|
||||
.WithDescription("Deletes an exercise for the specified user.");
|
||||
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,6 +160,23 @@ internal static class RoutineEndpoints
|
||||
.WithSummary("Update routine")
|
||||
.WithDescription("Updates routine metadata and exercise ordering.");
|
||||
|
||||
group.MapDelete("/users/{userId}/routines/{routineId:int}", async (string userId, int routineId, AppDbContext db) =>
|
||||
{
|
||||
var user = await UserProvisioning.EnsureUserAsync(db, userId);
|
||||
var routine = await db.Routines.FirstOrDefaultAsync(r => r.Id == routineId && r.UserId == user.Id);
|
||||
if (routine is null)
|
||||
{
|
||||
return Results.NotFound();
|
||||
}
|
||||
|
||||
db.Routines.Remove(routine);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return Results.NoContent();
|
||||
})
|
||||
.WithSummary("Delete routine")
|
||||
.WithDescription("Deletes a routine and its associated data for the specified user.");
|
||||
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user