Refactoring some Code and clean Code

This commit is contained in:
franc
2025-04-09 15:37:44 +02:00
parent d248ccb1db
commit 127a60b621
19 changed files with 132 additions and 114 deletions
@@ -13,7 +13,7 @@
Task RemoveIngredientFromRecipeAsync(Guid recipeId, Guid ingredientId);
Task<IEnumerable<Recipe>> GetRecipesByNameOrIngredientAsync(string name, string ingredient);
Task<IEnumerable<Recipe>> GetRecipesByNameAndIngredientAsync(string name, string ingredient);
Task<IReadOnlyCollection<Recipe>> GetRecipesByDifficultyAsync(Difficulty? difficulty);
@@ -37,6 +37,7 @@
.Include(r => r.RecipeIngredients)
.ThenInclude(ri => ri.Unit)
.Include(r => r.MediaFiles)
.Include(r => r.Instructions)
.FirstOrDefaultAsync(r => r.Id == recipeId);
}
@@ -53,7 +54,7 @@
var ingredients = await _ingredientRepository.GetIngredientsByNameAsync(ingredientName);
Ingredient ingredient;
if (ingredients == null || !ingredients.Any())
if (!ingredients.Any())
{
ingredient = new Ingredient
{
@@ -131,7 +132,6 @@
public async Task RemoveIngredientFromRecipeAsync(Guid recipeId, Guid ingredientId)
{
var recipe = await GetRecipeAsync(recipeId);
var recipeIngredient = await _context.RecipeIngredients
.FirstOrDefaultAsync(ri => ri.Recipe.Id == recipeId && ri.Ingredient.Id == ingredientId);
@@ -144,7 +144,7 @@
await _context.SaveChangesAsync();
}
public async Task<IEnumerable<Recipe>> GetRecipesByNameOrIngredientAsync(string name, string ingredient)
public async Task<IEnumerable<Recipe>> GetRecipesByNameAndIngredientAsync(string name, string ingredient)
{
var query = _context.Recipes
.Include(r => r.RecipeIngredients)