From e3bf8f503a0e56eaebbb5f4e639fd8a3176c50b5 Mon Sep 17 00:00:00 2001 From: Alexandre Agostinho Date: Wed, 31 May 2023 16:02:54 +0200 Subject: [PATCH] new manager interfaces --- MCTG/ConsoleApp/Program.cs | 2 +- MCTG/DataPersistence/DataContractJSON.cs | 2 +- MCTG/DataPersistence/DataContractXML.cs | 2 +- MCTG/DataPersistence/Stubs.cs | 2 +- MCTG/Model/Managers/DataManager.cs | 14 +++--- MCTG/Model/Managers/IDataManager.cs | 61 +++++++----------------- MCTG/Model/Managers/IDataSerializer.cs | 44 +++++++++++++++++ MCTG/Model/Managers/IRecipeManager.cs | 19 ++++++++ MCTG/Model/Managers/IUserManager.cs | 18 +++++++ MCTG/Model/Managers/MasterManager.cs | 2 +- 10 files changed, 110 insertions(+), 56 deletions(-) create mode 100644 MCTG/Model/Managers/IDataSerializer.cs create mode 100644 MCTG/Model/Managers/IRecipeManager.cs create mode 100644 MCTG/Model/Managers/IUserManager.cs diff --git a/MCTG/ConsoleApp/Program.cs b/MCTG/ConsoleApp/Program.cs index ff09c71..cf6c460 100644 --- a/MCTG/ConsoleApp/Program.cs +++ b/MCTG/ConsoleApp/Program.cs @@ -9,7 +9,7 @@ string path = ""; // - path to the save file string strategy = "xml"; // - strategy is 'xml' or 'json' (/!\ this is case sensitive) MasterManager masterMgr; -IDataManager dataManager = (strategy == "xml") ? +IDataSerializer dataManager = (strategy == "xml") ? new DataContractXML(path) : new DataContractJSON(path); diff --git a/MCTG/DataPersistence/DataContractJSON.cs b/MCTG/DataPersistence/DataContractJSON.cs index 13879b7..b0ae42d 100644 --- a/MCTG/DataPersistence/DataContractJSON.cs +++ b/MCTG/DataPersistence/DataContractJSON.cs @@ -14,7 +14,7 @@ namespace DataPersistence /// /// Define a serializer to manage JSON files. /// - public class DataContractJSON : IDataManager + public class DataContractJSON : IDataSerializer { #region Attributes private string _jsonFolderPath; diff --git a/MCTG/DataPersistence/DataContractXML.cs b/MCTG/DataPersistence/DataContractXML.cs index 910d26d..053c4ac 100644 --- a/MCTG/DataPersistence/DataContractXML.cs +++ b/MCTG/DataPersistence/DataContractXML.cs @@ -13,7 +13,7 @@ namespace DataPersistence /// /// Define a serializer to manage XML files. /// - public class DataContractXML : IDataManager + public class DataContractXML : IDataSerializer { #region Attributes private string _xmlFolderPath; diff --git a/MCTG/DataPersistence/Stubs.cs b/MCTG/DataPersistence/Stubs.cs index a6fece1..b842202 100644 --- a/MCTG/DataPersistence/Stubs.cs +++ b/MCTG/DataPersistence/Stubs.cs @@ -10,7 +10,7 @@ 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 class Stubs : IDataSerializer { public Dictionary> Load() { diff --git a/MCTG/Model/Managers/DataManager.cs b/MCTG/Model/Managers/DataManager.cs index 8ff3ff6..299d99f 100644 --- a/MCTG/Model/Managers/DataManager.cs +++ b/MCTG/Model/Managers/DataManager.cs @@ -16,9 +16,9 @@ namespace Model /// /// 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: + ///
See: ///
- public IDataManager Serializer { get; set; } + public IDataSerializer 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. @@ -31,7 +31,7 @@ namespace Model /// 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) + public DataManager(IDataSerializer dataMgr) { Serializer = dataMgr; Data = Serializer.Load(); @@ -41,21 +41,21 @@ namespace Model #region Methods /// /// Reload the data. Useful to update new data written in the save file. - ///
See: + ///
See: ///
public void Reload() => Data = Serializer.Load(); /// /// Save the data. Call the Save method of the serializer. - ///
See: + ///
See: ///
public void Save() => Serializer.Save(Data); /// /// Import data from a file. - ///
See: + ///
See: ///
/// The type of data to import. /// The path containing the name of the file created. @@ -68,7 +68,7 @@ namespace Model /// /// Export the data from the collection of data. - ///
See: + ///
See: ///
/// The type of data to export /// The object to export diff --git a/MCTG/Model/Managers/IDataManager.cs b/MCTG/Model/Managers/IDataManager.cs index c8a4ca6..ffb1aee 100644 --- a/MCTG/Model/Managers/IDataManager.cs +++ b/MCTG/Model/Managers/IDataManager.cs @@ -1,44 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model -{ - /// - /// Interface that define the methods of a data serializer. - /// - public interface IDataManager - { - /// - /// Save all the data in a file. - /// - /// The data to save. - void Save(Dictionary> elements); - - /// - /// Load all the data from a file. - /// - /// The data loaded. - Dictionary> Load(); - - /// - /// Import an element to the collection of data. - /// - /// The type of the element to impoert - /// The path containing the name of the file. - /// A pair where the key is the entry in the data and the value is the value to add on this entry. - public KeyValuePair Import(string pathToImport) - where T : class; - - /// - /// Export an element from the collection of data. - /// - /// The type of the exported object. - /// The object to export. - /// The path containing the name of the file created. - public void Export(T obj, string pathToExport) - where T : class; - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model.Managers +{ + public interface IDataManager + { + void LoadData(); + void ReloadData(); + void SaveData(); + void Import(string pathOfTheFile) where T : class; + void Export(T obj, string pathToExport) where T : class; + } +} diff --git a/MCTG/Model/Managers/IDataSerializer.cs b/MCTG/Model/Managers/IDataSerializer.cs new file mode 100644 index 0000000..eba0cb6 --- /dev/null +++ b/MCTG/Model/Managers/IDataSerializer.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model +{ + /// + /// Interface that define the methods of a data serializer. + /// + public interface IDataSerializer + { + /// + /// Save all the data in a file. + /// + /// The data to save. + void Save(Dictionary> elements); + + /// + /// Load all the data from a file. + /// + /// The data loaded. + Dictionary> Load(); + + /// + /// Import an element to the collection of data. + /// + /// The type of the element to impoert + /// The path containing the name of the file. + /// A pair where the key is the entry in the data and the value is the value to add on this entry. + public KeyValuePair Import(string pathToImport) + where T : class; + + /// + /// Export an element from the collection of data. + /// + /// The type of the exported object. + /// The object to export. + /// The path containing the name of the file created. + public void Export(T obj, string pathToExport) + where T : class; + } +} diff --git a/MCTG/Model/Managers/IRecipeManager.cs b/MCTG/Model/Managers/IRecipeManager.cs new file mode 100644 index 0000000..f9d7e00 --- /dev/null +++ b/MCTG/Model/Managers/IRecipeManager.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model.Managers +{ + public interface IRecipeManager + { + RecipeCollection GetAllRecipes(); + Recipe GetRecipeFromId(int id); + RecipeCollection GetRecipeByTitle(string title); + RecipeCollection GetRecipeByAuthor(string authorMail); + RecipeCollection GetRecipesByPriorityOrder(Priority priority); + bool AddRecipeToData(Recipe recipe); + bool ModifyRecipeInData(Recipe recipe); + } +} diff --git a/MCTG/Model/Managers/IUserManager.cs b/MCTG/Model/Managers/IUserManager.cs new file mode 100644 index 0000000..d86a404 --- /dev/null +++ b/MCTG/Model/Managers/IUserManager.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model.Managers +{ + public interface IUserManager + { + ICollection GetAllUsers(); + User GetUserFromMail(string mail); + bool AddUserToData(User user); + bool ModifyUserInData(User user); + bool LogIn(string mail, string password); + bool LogOut(); + } +} diff --git a/MCTG/Model/Managers/MasterManager.cs b/MCTG/Model/Managers/MasterManager.cs index 6bad13f..cd3cc83 100644 --- a/MCTG/Model/Managers/MasterManager.cs +++ b/MCTG/Model/Managers/MasterManager.cs @@ -41,7 +41,7 @@ namespace Model.Managers /// Constructor of the MasterManager. /// /// The serializer for the data. - public MasterManager(IDataManager dataManager) + public MasterManager(IDataSerializer dataManager) { DataMgr = new DataManager(dataManager); CurrentConnectedUser = null;