diff --git a/.drone.yml b/.drone.yml index 1e97fec..ab57284 100644 --- a/.drone.yml +++ b/.drone.yml @@ -85,7 +85,7 @@ steps: - name: docker-image-console-app image: plugins/docker settings: - dockerfile: MCTG/Dockerfile + dockerfile: MCTG/ConsoleApp/Dockerfile context: MCTG/ registry: hub.codefirst.iut.uca.fr repo: hub.codefirst.iut.uca.fr/alexandre.agostinho/console-mctg diff --git a/MCTG/CI-CD.slnf b/MCTG/CI-CD.slnf index 5728156..800dd29 100644 --- a/MCTG/CI-CD.slnf +++ b/MCTG/CI-CD.slnf @@ -3,7 +3,11 @@ "path": "SAE-2.01.sln", "projects": [ "ConsoleApp\\ConsoleApp.csproj", + "Exception\\AppException.csproj", + "Managers\\Managers.csproj", "Model\\Model.csproj", + "Persistance\\DataPersistence\\DataPersistence.csproj", + "Persistance\\FakePersistance\\FakePersistance.csproj", "Tests\\Model_UnitTests\\Model_UnitTests.csproj" ] } diff --git a/MCTG/Dockerfile b/MCTG/ConsoleApp/Dockerfile similarity index 100% rename from MCTG/Dockerfile rename to MCTG/ConsoleApp/Dockerfile diff --git a/MCTG/Managers/RecipeDefaultManager.cs b/MCTG/Managers/RecipeDefaultManager.cs index 223df4c..825c376 100644 --- a/MCTG/Managers/RecipeDefaultManager.cs +++ b/MCTG/Managers/RecipeDefaultManager.cs @@ -1,5 +1,7 @@ using AppException; using Model; +using System.Reflection; +using System.Runtime.CompilerServices; namespace Managers { @@ -63,18 +65,40 @@ namespace Managers return recipe; } - public RecipeCollection GetRecipesByPriorityOrder(Priority priority) + public RecipeCollection GetRecipesByPriorityOrder(IEnumerable priorities) { - IEnumerable recipes = from Recipe recipe in _dataManager.GetFromData() - where recipe.Priority == priority - select recipe; + List recipes = new List(); + IEnumerable recipesWithCurrentPriority; + foreach (Priority priority in priorities) + { + recipesWithCurrentPriority = from Recipe recipe in _dataManager.GetFromData() + where recipe.Priority == priority + select recipe; + recipes.AddRange(recipesWithCurrentPriority); + } + return new RecipeCollection( $"Suggestions", recipes.ToArray()); } - public bool ModifyRecipeInData(Recipe recipe) + public bool ModifyRecipeInData(Recipe oldRecipe, Recipe newRecipe) { - throw new NotImplementedException(); + if (oldRecipe.Equals(newRecipe)) + return false; + + Recipe? recipe = _dataManager.GetFromData() + .ToList() + .Find(r => r.Equals(oldRecipe)); + if (recipe is null) + throw new RecipeNotFoundException(); + + foreach (var property in typeof(Recipe).GetProperties() + .Where(prop => prop.CanWrite)) + { + property.SetValue(oldRecipe, recipe); + } + + return true; } } } diff --git a/MCTG/Model/Managers/IRecipeManager.cs b/MCTG/Model/Managers/IRecipeManager.cs index 5ccf642..08310a0 100644 --- a/MCTG/Model/Managers/IRecipeManager.cs +++ b/MCTG/Model/Managers/IRecipeManager.cs @@ -12,8 +12,8 @@ namespace Model Recipe GetRecipeFromId(int id); RecipeCollection GetRecipeByTitle(string title); RecipeCollection GetRecipeByAuthor(string authorMail); - RecipeCollection GetRecipesByPriorityOrder(Priority priority); + RecipeCollection GetRecipesByPriorityOrder(IEnumerable priority); bool AddRecipeToData(Recipe recipe); - bool ModifyRecipeInData(Recipe recipe); + bool ModifyRecipeInData(Recipe oldRecipe, Recipe newRecipe); } } diff --git a/MCTG/Tests/Model_UnitTests/Recipe_UT.cs b/MCTG/Tests/Model_UnitTests/Recipe_UT.cs index b98ab2a..6f7d8ef 100644 --- a/MCTG/Tests/Model_UnitTests/Recipe_UT.cs +++ b/MCTG/Tests/Model_UnitTests/Recipe_UT.cs @@ -8,7 +8,7 @@ namespace Model_UnitTests public void TestVoidConstructor() { Recipe r = new Recipe( - title: "test recipe", type: RecipeType.Unspecified); + title: "test recipe", type: RecipeType.Unspecified, priority: Priority.Easy); Assert.NotNull(r.Title); }