Add structured quantities + units to shopping list items
Mirrors the Phase 2 work on RecipeIngredient: ShoppingListItem grows Quantity (decimal), UnitOfMeasureId / FamilyUnitOfMeasureId, IsApproximate, and QuantityNote. The recipe-to-list copy now carries structured fields verbatim instead of folding them into the free-form Name, and the unit-in-use guard now also blocks deleting a family unit that's referenced by a shopping list item. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -119,10 +119,12 @@ public static class UnitEndpoints
|
||||
var unit = await db.FamilyUnitsOfMeasure.FirstOrDefaultAsync(u => u.Id == id && u.FamilyId == familyId);
|
||||
if (unit is null) return Results.NotFound();
|
||||
|
||||
// Block deletion when any recipe ingredient still references the
|
||||
// unit. (ShoppingListItem will gain the same check in Phase 3.)
|
||||
var inUse = await db.RecipeIngredients.AnyAsync(i => i.FamilyUnitOfMeasureId == id);
|
||||
if (inUse) return Results.Conflict(new { error = "Unit is in use by one or more recipes." });
|
||||
// Block deletion when any recipe ingredient or shopping list item
|
||||
// still references the unit.
|
||||
var inUseByRecipe = await db.RecipeIngredients.AnyAsync(i => i.FamilyUnitOfMeasureId == id);
|
||||
if (inUseByRecipe) return Results.Conflict(new { error = "Unit is in use by one or more recipes." });
|
||||
var inUseByList = await db.ShoppingListItems.AnyAsync(i => i.FamilyUnitOfMeasureId == id);
|
||||
if (inUseByList) return Results.Conflict(new { error = "Unit is in use by one or more shopping lists." });
|
||||
|
||||
db.FamilyUnitsOfMeasure.Remove(unit);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
Reference in New Issue
Block a user