Move Method Body on Repositroy and inject Repository on Service

This commit is contained in:
franc
2025-04-16 17:37:11 +02:00
parent 84c75098cf
commit c07cdf7eae
3 changed files with 18 additions and 8 deletions
@@ -17,5 +17,8 @@
Task DeleteShoppingListAsync(Guid shoppingListId);
Task<Recipe?> GetRecipeByNameAndImageAsync(string recipeName, string imageFileName);
Task<int> GetShoppingListRecipeCountAsync(Guid shoppingListId);
}
}
@@ -167,5 +167,12 @@
.Include(r => r.MediaFiles.Where(mf => mf.FileName == imageFileName))
.FirstOrDefaultAsync();
}
public async Task<int> GetShoppingListRecipeCountAsync(Guid shoppingListId)
{
return await _context.RecipeShoppingLists
.Where(rsl => rsl.ShoppingList.Id == shoppingListId)
.CountAsync();
}
}
}
@@ -1,22 +1,22 @@
using Francesco.Recipes.World.Data;
using Microsoft.EntityFrameworkCore;
namespace Francesco.Recipes.World.Services.ShoppingList
namespace Francesco.Recipes.World.Services.ShoppingList
{
using Francesco.Recipes.World.Data;
using Francesco.Recipes.World.Repositories.ShoppingList;
public class ShoppingListService
{
private readonly FrancescosRecipesWorldDbContext _context;
private readonly IShoppingListRepository _shoppingListRepository;
public ShoppingListService(FrancescosRecipesWorldDbContext context)
public ShoppingListService(FrancescosRecipesWorldDbContext context, IShoppingListRepository shoppingListRepository)
{
_context = context;
_shoppingListRepository = shoppingListRepository;
}
public async Task<int> GetShoppingListRecipeCountAsync(Guid shoppingListId)
{
return await _context.RecipeShoppingLists
.Where(rsl => rsl.ShoppingList.Id == shoppingListId)
.CountAsync();
return await _shoppingListRepository.GetShoppingListRecipeCountAsync(shoppingListId);
}
}
}