add recipe managment
This commit is contained in:
@@ -2,12 +2,13 @@
|
||||
{
|
||||
using Francesco.Recipes.World.Models.BackendModels.Category;
|
||||
using Francesco.Recipes.World.Models.BackendModels.Recipe;
|
||||
using Francesco.Recipes.World.Models.BackendModels.Unit;
|
||||
|
||||
public interface IRecipeRepository
|
||||
{
|
||||
Task<Recipe> GetRecipeAsync(Guid recipeId);
|
||||
|
||||
Task<Recipe?> GetRecipeByIdAsync(Guid id);
|
||||
|
||||
Task AddOrCreateIngredientToRecipeAsync(Guid recipeId, string ingredientName, int quantity, Guid unitId);
|
||||
|
||||
Task RemoveIngredientFromRecipeAsync(Guid recipeId, Guid ingredientId);
|
||||
@@ -16,8 +17,6 @@
|
||||
|
||||
Task<IReadOnlyCollection<Recipe>> GetRecipesByDifficultyAsync(Difficulty? difficulty);
|
||||
|
||||
Task<Unit> AddUnitToRecipeAsync(string name, string symbol);
|
||||
|
||||
Task<Recipe> CreateRecipeForCategoryAsync(Category category, string name, string description, Difficulty difficulty, int servings, TimeSpan preparationTime, TimeSpan cookingTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
using Francesco.Recipes.World.Models.BackendModels.Ingredient;
|
||||
using Francesco.Recipes.World.Models.BackendModels.Recipe;
|
||||
using Francesco.Recipes.World.Models.BackendModels.RecipeIngredient;
|
||||
using Francesco.Recipes.World.Models.BackendModels.Unit;
|
||||
using Francesco.Recipes.World.Repositories.Ingredient;
|
||||
using Francesco.Recipes.World.Repositories.Unit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -30,6 +29,17 @@
|
||||
return recipe ?? throw new InvalidDataException($"Address {recipeId} not found.");
|
||||
}
|
||||
|
||||
public async Task<Recipe?> GetRecipeByIdAsync(Guid recipeId)
|
||||
{
|
||||
return await _context.Recipes
|
||||
.Include(r => r.RecipeIngredients)
|
||||
.ThenInclude(ri => ri.Ingredient)
|
||||
.Include(r => r.RecipeIngredients)
|
||||
.ThenInclude(ri => ri.Unit)
|
||||
.Include(r => r.MediaFiles)
|
||||
.FirstOrDefaultAsync(r => r.Id == recipeId);
|
||||
}
|
||||
|
||||
public async Task AddOrCreateIngredientToRecipeAsync(Guid recipeId, string ingredientName, int quantity, Guid unitId)
|
||||
{
|
||||
var recipe = await GetRecipeAsync(recipeId);
|
||||
@@ -77,13 +87,13 @@
|
||||
}
|
||||
|
||||
public async Task<Recipe> CreateRecipeForCategoryAsync(
|
||||
Category category,
|
||||
string name,
|
||||
string description,
|
||||
Difficulty difficulty,
|
||||
int servings,
|
||||
TimeSpan preparationTime,
|
||||
TimeSpan cookingTime)
|
||||
Category category,
|
||||
string name,
|
||||
string description,
|
||||
Difficulty difficulty,
|
||||
int servings,
|
||||
TimeSpan preparationTime,
|
||||
TimeSpan cookingTime)
|
||||
{
|
||||
if (category == null)
|
||||
{
|
||||
@@ -162,14 +172,21 @@
|
||||
|
||||
public async Task<IReadOnlyCollection<Recipe>> GetRecipesByDifficultyAsync(Difficulty? difficulty)
|
||||
{
|
||||
return await _context.Recipes
|
||||
.Where(r => r.Difficulty == difficulty)
|
||||
.ToListAsync();
|
||||
}
|
||||
if (!difficulty.HasValue)
|
||||
{
|
||||
return await _context.Recipes
|
||||
.Include(r => r.Category)
|
||||
.Include(r => r.RecipeIngredients)
|
||||
.ThenInclude(ri => ri.Ingredient)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<Unit> AddUnitToRecipeAsync(string name, string symbol)
|
||||
{
|
||||
return await _unitRepository.AddUnitAsync(name, symbol);
|
||||
return await _context.Recipes
|
||||
.Where(r => r.Difficulty == difficulty.Value)
|
||||
.Include(r => r.Category)
|
||||
.Include(r => r.RecipeIngredients)
|
||||
.ThenInclude(ri => ri.Ingredient)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user