From 385be506a7e57630c514bb358fa722cd254a3379 Mon Sep 17 00:00:00 2001 From: Francesco Lorenzo D'Amico Date: Mon, 19 May 2025 13:25:35 +0200 Subject: [PATCH] Implement a method to get whole shoppinglist model --- .../ShoppingList/IShoppingListRepository.cs | 2 ++ .../ShoppingList/ShoppingListRepository.cs | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/Francesco.Recipes.World/Repositories/ShoppingList/IShoppingListRepository.cs b/Francesco.Recipes.World/Repositories/ShoppingList/IShoppingListRepository.cs index c14f0aa..3b30be5 100644 --- a/Francesco.Recipes.World/Repositories/ShoppingList/IShoppingListRepository.cs +++ b/Francesco.Recipes.World/Repositories/ShoppingList/IShoppingListRepository.cs @@ -18,6 +18,8 @@ Task GetRecipeByNameAndImageAsync(string recipeName, string imageFileName); + Task GetByIdAsync(Guid shoppingListId); + Task CountAllRecipeShoppinglistsAsync(); } } diff --git a/Francesco.Recipes.World/Repositories/ShoppingList/ShoppingListRepository.cs b/Francesco.Recipes.World/Repositories/ShoppingList/ShoppingListRepository.cs index 1e64469..f49bfce 100644 --- a/Francesco.Recipes.World/Repositories/ShoppingList/ShoppingListRepository.cs +++ b/Francesco.Recipes.World/Repositories/ShoppingList/ShoppingListRepository.cs @@ -109,6 +109,22 @@ return shoppingList; } + public async Task 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> GetIngredientsOfRecipeInListAsync(Guid shoppingListRecipeId) { return await _context.RecipeIngredientsShoppingLists