Implement a method to get whole shoppinglist model

This commit is contained in:
Francesco Lorenzo D'Amico
2025-05-19 13:25:35 +02:00
parent 00cd006bf8
commit 385be506a7
2 changed files with 18 additions and 0 deletions
@@ -18,6 +18,8 @@
Task<Recipe?> GetRecipeByNameAndImageAsync(string recipeName, string imageFileName);
Task<ShoppingList?> GetByIdAsync(Guid shoppingListId);
Task<int> CountAllRecipeShoppinglistsAsync();
}
}
@@ -109,6 +109,22 @@
return shoppingList;
}
public async Task<ShoppingList?> GetByIdAsync(Guid shoppingListId)
{
return await _context.ShoppingLists
.Include(sl => sl.RecipeShoppingList)
.ThenInclude(rsl => rsl.Recipe)
.Include(sl => sl.RecipeShoppingList)
.ThenInclude(rsl => rsl.SelectedIngredients)
.ThenInclude(si => si.RecipeIngredient)
.ThenInclude(ri => ri.Ingredient)
.Include(sl => sl.RecipeShoppingList)
.ThenInclude(rsl => rsl.SelectedIngredients)
.ThenInclude(si => si.RecipeIngredient)
.ThenInclude(ri => ri.Unit)
.FirstOrDefaultAsync(sl => sl.Id == shoppingListId);
}
public async Task<IEnumerable<RecipeIngredientShoppingList>> GetIngredientsOfRecipeInListAsync(Guid shoppingListRecipeId)
{
return await _context.RecipeIngredientsShoppingLists