Move Method Body on Repositroy and inject Repository on Service
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user