Add per-store sections to group list items by walk order
Each store gets a StoreSection catalog (Produce, Dairy, etc.). Default sections are seeded on store creation; admins can rename, reorder, add, or delete. ShoppingListItem.SectionId is a nullable FK that sets to null when the section is deleted, so items survive section churn. The list detail view groups items by section in walk order, with Uncategorized appended last. Section dropdowns on each row (and the add-item form) let users assign or reassign on the fly. SignalR broadcasts include sectionId on adds and a new ItemSectionChanged event for live re-grouping. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ public class YesChefDb(DbContextOptions<YesChefDb> options) : DbContext(options)
|
||||
public DbSet<FamilyMembership> FamilyMemberships => Set<FamilyMembership>();
|
||||
public DbSet<User> Users => Set<User>();
|
||||
public DbSet<Store> Stores => Set<Store>();
|
||||
public DbSet<StoreSection> StoreSections => Set<StoreSection>();
|
||||
public DbSet<ShoppingList> ShoppingLists => Set<ShoppingList>();
|
||||
public DbSet<ShoppingListItem> ShoppingListItems => Set<ShoppingListItem>();
|
||||
public DbSet<Recipe> Recipes => Set<Recipe>();
|
||||
@@ -44,6 +45,14 @@ public class YesChefDb(DbContextOptions<YesChefDb> options) : DbContext(options)
|
||||
e.Property(s => s.Name).HasMaxLength(100);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<StoreSection>(e =>
|
||||
{
|
||||
e.HasOne(s => s.Family).WithMany().HasForeignKey(s => s.FamilyId).OnDelete(DeleteBehavior.Cascade);
|
||||
e.HasOne(s => s.Store).WithMany().HasForeignKey(s => s.StoreId).OnDelete(DeleteBehavior.Cascade);
|
||||
e.HasIndex(s => new { s.StoreId, s.Name }).IsUnique();
|
||||
e.Property(s => s.Name).HasMaxLength(100);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<ShoppingList>(e =>
|
||||
{
|
||||
e.Property(l => l.Name).HasMaxLength(200);
|
||||
@@ -61,6 +70,7 @@ public class YesChefDb(DbContextOptions<YesChefDb> options) : DbContext(options)
|
||||
e.HasOne(i => i.CheckedByUser).WithMany().HasForeignKey(i => i.CheckedByUserId).OnDelete(DeleteBehavior.SetNull);
|
||||
e.HasOne(i => i.RemovedByUser).WithMany().HasForeignKey(i => i.RemovedByUserId).OnDelete(DeleteBehavior.SetNull);
|
||||
e.HasOne(i => i.Recipe).WithMany().HasForeignKey(i => i.RecipeId).OnDelete(DeleteBehavior.SetNull);
|
||||
e.HasOne(i => i.Section).WithMany().HasForeignKey(i => i.SectionId).OnDelete(DeleteBehavior.SetNull);
|
||||
e.HasIndex(i => i.FamilyId);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user