diff --git a/MCTG/ConsoleApp/ConsoleApp - Backup.csproj b/MCTG/ConsoleApp/ConsoleApp - Backup.csproj new file mode 100644 index 0000000..2c5123f --- /dev/null +++ b/MCTG/ConsoleApp/ConsoleApp - Backup.csproj @@ -0,0 +1,16 @@ + + + + Exe + net7.0 + enable + enable + Debug;Release;CI + + + + + + + + diff --git a/MCTG/ConsoleApp/ConsoleApp.csproj b/MCTG/ConsoleApp/ConsoleApp.csproj index 2c5123f..dbc5e22 100644 --- a/MCTG/ConsoleApp/ConsoleApp.csproj +++ b/MCTG/ConsoleApp/ConsoleApp.csproj @@ -5,12 +5,11 @@ net7.0 enable enable - Debug;Release;CI - - - + + + diff --git a/MCTG/ConsoleApp/Menu/AddRecipeMenu.cs b/MCTG/ConsoleApp/Menu/AddRecipeMenu.cs index c6ef6f2..7fc51f4 100644 --- a/MCTG/ConsoleApp/Menu/AddRecipeMenu.cs +++ b/MCTG/ConsoleApp/Menu/AddRecipeMenu.cs @@ -41,6 +41,7 @@ namespace ConsoleApp.Menu title: title, id: null, authorMail: MasterManager.CurrentConnectedUser?.Mail, + picture: "", ingredients: new List(), preparationSteps: steps.ToArray() ); diff --git a/MCTG/ConsoleApp/Program.cs b/MCTG/ConsoleApp/Program.cs index 3a5da0c..ff09c71 100644 --- a/MCTG/ConsoleApp/Program.cs +++ b/MCTG/ConsoleApp/Program.cs @@ -23,6 +23,7 @@ else masterMgr = new MasterManager(dataManager); } + MenuManager menuMgr = new MenuManager(masterMgr); menuMgr.Loop(); diff --git a/MCTG/DataPersistence/Stubs.cs b/MCTG/DataPersistence/Stubs.cs index 4234eb1..87e62b9 100644 --- a/MCTG/DataPersistence/Stubs.cs +++ b/MCTG/DataPersistence/Stubs.cs @@ -1,104 +1,108 @@ -using Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DataPersistence -{ - /// - /// The subs class is a group of prefabricated object that can only be loaded. It only use is for testing. - /// - public class Stubs : IDataManager - { - public Dictionary> Load() - { - Dictionary> data = new Dictionary> - { - { - #region Data: Recipes - nameof(Recipe), - new List(new[] - { - new Recipe( - title: "Cookies classiques", id: null, - authorMail: "admin@mctg.fr", - ingredients: new List(new[] +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataPersistence +{ + /// + /// The subs class is a group of prefabricated object that can only be loaded. It only use is for testing. + /// + public class Stubs : IDataManager + { + public Dictionary> Load() + { + Dictionary> data = new Dictionary> + { + { + #region Data: Recipes + nameof(Recipe), + new List(new[] + { + new Recipe( + title: "Cookies classiques", + id: 50, + authorMail: "admin@mctg.fr", + picture : "room_service_icon.png", + ingredients: new List(new[] { new Ingredient("Patates", new Quantity(23, Unit.unit)), new Ingredient("Farine", new Quantity(23, Unit.G)) - }), - preparationSteps: new[] - { - new PreparationStep(1, "Faire cuire."), - new PreparationStep(2, "Manger.") - }), - new Recipe( - authorMail: "admin@mctg.fr", - title: "Cookies au chocolat", id: null, - preparationSteps: new[] - { - new PreparationStep(1, "Moulinez la pâte."), - new PreparationStep(2, "Faire cuire pendant une bonne heure."), - new PreparationStep(3, "Sortir du four et mettre dans un plat.") - }), - new Recipe( - title: "Gateau nature", id: null, - authorMail: "admin@mctg.fr", - preparationSteps: new[] - { - new PreparationStep(1, "Achetez les ingrédients."), - new PreparationStep(2, "Préparez le matériel. Ustensiles et tout."), - new PreparationStep(3, "Pleurez.") - }), - new Recipe( - title: "Gateau au pommes", id: null, - authorMail: "admin@mctg.fr", - preparationSteps: new[] - { - new PreparationStep(1, "Achetez les légumes."), - new PreparationStep(2, "Préparez le plat. Ustensiles et préchauffez le four."), - new PreparationStep(3, "Coupez les pommes en morceaux et disposez-les sur le plat."), - new PreparationStep(4, "Mettez enfin le plat au four, puis une fois cuit, dégustez !") - }), - new Recipe( - title: "Gateau au chocolat", id: null, - authorMail: "pedrosamigos@hotmail.com", - preparationSteps: new[] - { - new PreparationStep(1, "Ajouter les oeufs."), - new PreparationStep(2, "Ajouter la farine."), - new PreparationStep(3, "Ajouter 100g de chocolat fondu."), - new PreparationStep(4, "Mélanger le tout."), - new PreparationStep(5, "Faire cuire 45h au four traditionnel.") - }), - new Recipe( - title: "Dinde au jambon", id: null, - authorMail: "pedrosamigos@hotmail.com", - preparationSteps: new[] - { - new PreparationStep(1, "Faire une cuisson bien sec de la dinde à la poêle"), - new PreparationStep(2, "Mettre la dinde au frigo."), - new PreparationStep(3, "Mettre le jambon dans le micro-onde."), - new PreparationStep(4, "Faire chauffer 3min."), - new PreparationStep(5, "Présentez sur un plat la dinde et le jambon : Miam !") - }), - new Recipe( - title: "Poulet au curry", id: null, - authorMail: "pedrosamigos@hotmail.com", - preparationSteps: new[] - { - new PreparationStep(1, "Trouvez des épices de curry."), - new PreparationStep(2, "Trouvez maintenant du poulet."), - new PreparationStep(3, "Coupez la tête du poulet et posez-la dans un plat."), - new PreparationStep(4, "Parsemez d'épices curry la tête de la poule."), - new PreparationStep(5, "Mettre le tout au four traditionnel 30min."), - new PreparationStep(6, "Dégustez en famille !") - }) - }) - #endregion + }), + preparationSteps: new[] + { + new PreparationStep(1, "Faire cuire."), + new PreparationStep(2, "Manger.") + }), + new Recipe( + authorMail: "admin@mctg.fr", + title: "Cookies au chocolat", id: null, + preparationSteps: new[] + { + new PreparationStep(1, "Moulinez la pâte."), + new PreparationStep(2, "Faire cuire pendant une bonne heure."), + new PreparationStep(3, "Sortir du four et mettre dans un plat.") + }), + new Recipe( + title: "Gateau nature", id: null, + authorMail: "admin@mctg.fr", + preparationSteps: new[] + { + new PreparationStep(1, "Achetez les ingrédients."), + new PreparationStep(2, "Préparez le matériel. Ustensiles et tout."), + new PreparationStep(3, "Pleurez.") + }), + new Recipe( + title: "Gateau au pommes", id: null, + authorMail: "admin@mctg.fr", + preparationSteps: new[] + { + new PreparationStep(1, "Achetez les légumes."), + new PreparationStep(2, "Préparez le plat. Ustensiles et préchauffez le four."), + new PreparationStep(3, "Coupez les pommes en morceaux et disposez-les sur le plat."), + new PreparationStep(4, "Mettez enfin le plat au four, puis une fois cuit, dégustez !") + }), + new Recipe( + title: "Gateau au chocolat", id: null, + authorMail: "pedrosamigos@hotmail.com", + preparationSteps: new[] + { + new PreparationStep(1, "Ajouter les oeufs."), + new PreparationStep(2, "Ajouter la farine."), + new PreparationStep(3, "Ajouter 100g de chocolat fondu."), + new PreparationStep(4, "Mélanger le tout."), + new PreparationStep(5, "Faire cuire 45h au four traditionnel.") + }), + new Recipe( + title: "Dinde au jambon", + id: null, + authorMail: "pedrosamigos@hotmail.com", + preparationSteps: new[] + { + new PreparationStep(1, "Faire une cuisson bien sec de la dinde à la poêle"), + new PreparationStep(2, "Mettre la dinde au frigo."), + new PreparationStep(3, "Mettre le jambon dans le micro-onde."), + new PreparationStep(4, "Faire chauffer 3min."), + new PreparationStep(5, "Présentez sur un plat la dinde et le jambon : Miam !") + }), + new Recipe( + title: "Poulet au curry", id: null, + authorMail: "pedrosamigos@hotmail.com", + preparationSteps: new[] + { + new PreparationStep(1, "Trouvez des épices de curry."), + new PreparationStep(2, "Trouvez maintenant du poulet."), + new PreparationStep(3, "Coupez la tête du poulet et posez-la dans un plat."), + new PreparationStep(4, "Parsemez d'épices curry la tête de la poule."), + new PreparationStep(5, "Mettre le tout au four traditionnel 30min."), + new PreparationStep(6, "Dégustez en famille !") + }) + }) + #endregion }, + { #region Data: User nameof(User), diff --git a/MCTG/Model/Managers/DataManager.cs b/MCTG/Model/Managers/DataManager.cs index d84f433..8ff3ff6 100644 --- a/MCTG/Model/Managers/DataManager.cs +++ b/MCTG/Model/Managers/DataManager.cs @@ -1,105 +1,105 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model -{ - /// - /// Define the manager of the data. This is where all the data are put, and where we call the loading and the saving of them. - /// - public class DataManager - { - #region Attributes & Properties - /// - /// The data manager injected that know how to serialize the data. - ///
The setter is actually public for testing purpose. It will be private after. - ///
See: - ///
- public IDataManager Serializer { get; set; } - - /// - /// The collection of all data. Each line of this dictionary has the type of the data as it key and the data for values. - /// - public Dictionary> Data { get; private set; } - #endregion - - #region Constructors - /// - /// Constructor of the DataManager class. Take a IDataManager that will provide methods for the serialisation of the data. - /// - /// The data manager that know how to serialize a file. - public DataManager(IDataManager dataMgr) - { - Serializer = dataMgr; - Data = Serializer.Load(); - } - #endregion - - #region Methods - /// - /// Reload the data. Useful to update new data written in the save file. - ///
See: - ///
- public void Reload() - => Data = Serializer.Load(); - - /// - /// Save the data. Call the Save method of the serializer. - ///
See: - ///
- public void Save() - => Serializer.Save(Data); - - /// - /// Import data from a file. - ///
See: - ///
- /// The type of data to import. - /// The path containing the name of the file created. - public void Import(string pathOfTheFile) - where T : class - { - KeyValuePair import = Serializer.Import(pathOfTheFile); - Data[import.Key].Add(import.Value); - } - - /// - /// Export the data from the collection of data. - ///
See: - ///
- /// The type of data to export - /// The object to export - /// The path containing the name of the file created. - public void Export(T obj, string pathToExport) - where T : class - => Serializer.Export(obj, pathToExport); - +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model +{ + /// + /// Define the manager of the data. This is where all the data are put, and where we call the loading and the saving of them. + /// + public class DataManager + { + #region Attributes & Properties + /// + /// The data manager injected that know how to serialize the data. + ///
The setter is actually public for testing purpose. It will be private after. + ///
See: + ///
+ public IDataManager Serializer { get; set; } + + /// + /// The collection of all data. Each line of this dictionary has the type of the data as it key and the data for values. + /// + public Dictionary> Data { get; private set; } + #endregion + + #region Constructors + /// + /// Constructor of the DataManager class. Take a IDataManager that will provide methods for the serialisation of the data. + /// + /// The data manager that know how to serialize a file. + public DataManager(IDataManager dataMgr) + { + Serializer = dataMgr; + Data = Serializer.Load(); + } + #endregion + + #region Methods + /// + /// Reload the data. Useful to update new data written in the save file. + ///
See: + ///
+ public void Reload() + => Data = Serializer.Load(); + + /// + /// Save the data. Call the Save method of the serializer. + ///
See: + ///
+ public void Save() + => Serializer.Save(Data); + + /// + /// Import data from a file. + ///
See: + ///
+ /// The type of data to import. + /// The path containing the name of the file created. + public void Import(string pathOfTheFile) + where T : class + { + KeyValuePair import = Serializer.Import(pathOfTheFile); + Data[import.Key].Add(import.Value); + } + + /// + /// Export the data from the collection of data. + ///
See: + ///
+ /// The type of data to export + /// The object to export + /// The path containing the name of the file created. + public void Export(T obj, string pathToExport) + where T : class + => Serializer.Export(obj, pathToExport); + /// /// Get all the recipe from the data. /// /// The title to give for the Recipe Collection - /// A RecipeCollection that contain all the recipe in the data. + /// A RecipeCollection that contain all the recipe in the data. public RecipeCollection GetRecipes(string rcTitle = "default") - => new RecipeCollection(rcTitle, Data[nameof(Recipe)].Cast().ToArray()); - + => new RecipeCollection(rcTitle, Data[nameof(Recipe)].Cast().ToArray()); + /// /// Get all the Users from the data. /// - /// A list of all Users. - public List GetUsers() - => new List(Data[nameof(User)].Cast()); - + /// A list of all Users. + public List GetUsers() + => new List(Data[nameof(User)].Cast()); + /// /// Get a list of an item in the data. /// /// The type of the item - /// The list of all the item found in the data. - public ICollection GetFromData() where T : class - => new List(Data[typeof(T).Name].Cast()); - - #endregion - } -} + /// The list of all the item found in the data. + public ICollection GetFromData() where T : class + => new List(Data[typeof(T).Name].Cast()); + + #endregion + } +} diff --git a/MCTG/Model/Recipes/Recipe.cs b/MCTG/Model/Recipes/Recipe.cs index 2f1906f..dc5cf2c 100644 --- a/MCTG/Model/Recipes/Recipe.cs +++ b/MCTG/Model/Recipes/Recipe.cs @@ -16,6 +16,9 @@ namespace Model #region Attributes [DataMember(Name = "title")] private string _title = ""; + + [DataMember(Name = "image")] + private string _image = ""; #endregion #region Properties @@ -54,11 +57,26 @@ namespace Model } /// + /// The image of the recipe.
+ /// Set to "room_service_icon.png" when the value passed is null, empty or contain white space. + ///
+ public string? Image + { + get => _image; + set + { + if (!string.IsNullOrWhiteSpace(value)) + _image = "room_service_icon.png"; + _image = value; + } + } + /// The list of ingredients. /// [DataMember(Name = "ingredient")] public List Ingredients { get; set; } + /// /// The steps of the preparation. See: . /// @@ -72,14 +90,17 @@ namespace Model /// /// The title of the recipe /// The id of the recipe. If not given, get a new id. + /// The name of the user that create this recipe. + /// The image that represent the recipe /// Thr list of reviews. /// Thr list of ingredients. /// The steps of the preparation of the meal - public Recipe(string title, int? id, string? authorMail, + public Recipe(string title, int? id, string? authorMail, string? picture, List reviews, List ingredients, params PreparationStep[] preparationSteps) { Title = title; + Image = picture; PreparationSteps = new List(preparationSteps); Ingredients = ingredients; Reviews = reviews; @@ -95,47 +116,18 @@ namespace Model else Id = (int)id; } - /// - /// - /// - /// The title of the recipe. - public Recipe(string title) - : this(title, null, null, new List(), new List()) - { - } - - /// - /// - /// - /// The title of the recipe. - /// The steps of the preparation of the meal. - public Recipe(string title, params PreparationStep[] preparationSteps) - : this(title, null, null, new List(), new List(), preparationSteps) - { - } /// /// /// /// The title of the recipe. /// The id of the recipe. If not given, get a new id. + /// Mail of the user that create the recipe /// The steps of the preparation of the meal. - public Recipe(string title, int? id, params PreparationStep[] preparationSteps) - : this(title, id, null, new List(), new List(), preparationSteps) + public Recipe(string title, int? id, string? authorMail, params PreparationStep[] preparationSteps) + : this(title, id, authorMail, null, new List(), new List(), preparationSteps) { - } - /// - /// - /// - /// The title of the recipe. - /// The id of the recipe. If not given, get a new id. - /// Thr list of ingredients. - /// The steps of the preparation of the meal. - public Recipe(string title, int? id, List ingredients, - params PreparationStep[] preparationSteps) - : this(title, id, null, new List(), ingredients, preparationSteps) - { } /// @@ -143,22 +135,27 @@ namespace Model /// /// The title of the recipe. /// The id of the recipe. If not given, get a new id. + /// Mail of the user that create the recipe + /// Mail of the user that create the recipe + /// List of ingredients that compose the recipe. /// The steps of the preparation of the meal. - public Recipe(string title, int? id, string? authorMail, List ingredients, params PreparationStep[] preparationSteps) - : this(title, id, authorMail, new List(), ingredients, preparationSteps) + public Recipe(string title, int? id, string? authorMail, string? picture, List ingredients, params PreparationStep[] preparationSteps) + : this(title, id, authorMail, picture, new List(), ingredients, preparationSteps) { } - /// - /// - /// - /// The title of the recipe. - /// The id of the recipe. If not given, get a new id. - /// The steps of the preparation of the meal. - public Recipe(string title, int? id, string? authorMail, params PreparationStep[] preparationSteps) - : this(title, id, authorMail, new List(), new List(), preparationSteps) - { - } + ///// + ///// + ///// + ///// The title of the recipe. + ///// The id of the recipe. If not given, get a new id. + ///// Image that reppresent the recipe. + ///// The steps of the preparation of the meal. + //public Recipe(string title, int? id, string picture, params PreparationStep[] preparationSteps) + // : this(title, id, null, picture, new List(), new List(), preparationSteps) + //{ + //} + #endregion #region Methods diff --git a/MCTG/Tests/Model_UnitTests/RecipeCollection_UT.cs b/MCTG/Tests/Model_UnitTests/RecipeCollection_UT.cs index b79b884..da0eb72 100644 --- a/MCTG/Tests/Model_UnitTests/RecipeCollection_UT.cs +++ b/MCTG/Tests/Model_UnitTests/RecipeCollection_UT.cs @@ -3,8 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; - +using DataPersistence; using Model; +using Model.Managers; namespace Model_UnitTests { @@ -13,18 +14,12 @@ namespace Model_UnitTests [Fact] public void TestResearchByName() { - RecipeCollection recipes = new RecipeCollection( - description: "test recipe", - recipes: new[] - { - new Recipe(title: "Gateau à la crème"), - new Recipe(title: "Gateau au chocolat"), - new Recipe(title: "Gateau aux cerises") - }); + MasterManager masterManager = new MasterManager(new Stubs()); + RecipeCollection recipes = masterManager.DataMgr.GetRecipes("test rc"); Recipe? search_result = recipes.ResearchByName("chocolat").FirstOrDefault(); Assert.NotNull(search_result); - Assert.Equal("Gateau au chocolat", search_result.Title); + Assert.Equal("Cookies au chocolat", search_result.Title); } } } diff --git a/MCTG/Tests/Model_UnitTests/Recipe_UT.cs b/MCTG/Tests/Model_UnitTests/Recipe_UT.cs index 4fdce86..a16deb8 100644 --- a/MCTG/Tests/Model_UnitTests/Recipe_UT.cs +++ b/MCTG/Tests/Model_UnitTests/Recipe_UT.cs @@ -7,7 +7,10 @@ namespace Model_UnitTests [Fact] public void TestVoidConstructor() { - Recipe r = new Recipe(""); // id is given to avoid tests errors with the static atrribute 'idCreator'. + Recipe r = new Recipe( + title: "test recipe", + id: null, + authorMail: "test@test.fr"); Assert.NotNull(r.Title); } } diff --git a/MCTG/Views/AddRecipe.xaml b/MCTG/Views/AddRecipe.xaml new file mode 100644 index 0000000..3f2460b --- /dev/null +++ b/MCTG/Views/AddRecipe.xaml @@ -0,0 +1,80 @@ + + + + + +