diff --git a/Francesco.Recipes.World/Repositories/ShoppingList/IShoppingListRepository.cs b/Francesco.Recipes.World/Repositories/ShoppingList/IShoppingListRepository.cs index 3b30be5..65e438a 100644 --- a/Francesco.Recipes.World/Repositories/ShoppingList/IShoppingListRepository.cs +++ b/Francesco.Recipes.World/Repositories/ShoppingList/IShoppingListRepository.cs @@ -21,5 +21,7 @@ Task GetByIdAsync(Guid shoppingListId); Task CountAllRecipeShoppinglistsAsync(); + + Task> GetAllShoppingListsAsync(); } } diff --git a/Francesco.Recipes.World/Repositories/ShoppingList/ShoppingListRepository.cs b/Francesco.Recipes.World/Repositories/ShoppingList/ShoppingListRepository.cs index f49bfce..d101931 100644 --- a/Francesco.Recipes.World/Repositories/ShoppingList/ShoppingListRepository.cs +++ b/Francesco.Recipes.World/Repositories/ShoppingList/ShoppingListRepository.cs @@ -111,20 +111,17 @@ 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) + return await GetShoppingListQuery() .FirstOrDefaultAsync(sl => sl.Id == shoppingListId); } + public async Task> GetAllShoppingListsAsync() + { + return await GetShoppingListQuery() + .OrderByDescending(sl => sl.CreatedAt) + .ToListAsync(); + } + public async Task> GetIngredientsOfRecipeInListAsync(Guid shoppingListRecipeId) { return await _context.RecipeIngredientsShoppingLists @@ -189,5 +186,21 @@ return await _context.RecipeShoppingLists .CountAsync(); } + + private IQueryable GetShoppingListQuery() + { + return _context.ShoppingLists + .Include(sl => sl.RecipeShoppingList) + .ThenInclude(rsl => rsl.Recipe) + .ThenInclude(r => r.MediaFiles) + .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); + } } }