From 0f4071f465467e17bb7610b4f247ab728353c7ef Mon Sep 17 00:00:00 2001 From: Alexandre Agostinho Date: Thu, 1 Jun 2023 09:52:19 +0200 Subject: [PATCH] add documentation on new code --- MCTG/ConsoleApp/Menu/AddUserMenu.cs | 2 +- MCTG/Managers/UserDefaultManager.cs | 3 +- MCTG/Model/Managers/IDataManager.cs | 3 ++ MCTG/Model/Managers/IPasswordManager.cs | 16 ++++++++- MCTG/Model/Managers/IRecipeManager.cs | 46 +++++++++++++++++++++++++ MCTG/Model/Managers/IUserManager.cs | 40 ++++++++++++++++++++- 6 files changed, 106 insertions(+), 4 deletions(-) diff --git a/MCTG/ConsoleApp/Menu/AddUserMenu.cs b/MCTG/ConsoleApp/Menu/AddUserMenu.cs index 41acc62..49d6a57 100644 --- a/MCTG/ConsoleApp/Menu/AddUserMenu.cs +++ b/MCTG/ConsoleApp/Menu/AddUserMenu.cs @@ -24,7 +24,7 @@ namespace ConsoleApp.Menu string surname = _selectList[2].Item.Input; string passwd = _selectList[3].Item.Input; - User user = masterMgr.User.CreateUser(name, surname, mail, passwd, null); + User user = masterMgr.User.CreateUser(mail, passwd, name, surname); masterMgr.User.AddUserToData(user); return null; diff --git a/MCTG/Managers/UserDefaultManager.cs b/MCTG/Managers/UserDefaultManager.cs index c96a662..db94186 100644 --- a/MCTG/Managers/UserDefaultManager.cs +++ b/MCTG/Managers/UserDefaultManager.cs @@ -41,7 +41,8 @@ namespace Managers return true; } - public User CreateUser(string? name, string? surname, string mail, string password, string? profilePict) + public User CreateUser(string mail, string password, + string? name = null, string? surname = null, string? profilePict = null) { if (name is null) name = $"user{GetRandomInt()}"; if (surname is null) surname = ""; diff --git a/MCTG/Model/Managers/IDataManager.cs b/MCTG/Model/Managers/IDataManager.cs index 267c4af..ccd40c7 100644 --- a/MCTG/Model/Managers/IDataManager.cs +++ b/MCTG/Model/Managers/IDataManager.cs @@ -7,6 +7,9 @@ using System.Threading.Tasks; namespace Model { + /// + /// Define how to manage data. + /// public interface IDataManager { /// diff --git a/MCTG/Model/Managers/IPasswordManager.cs b/MCTG/Model/Managers/IPasswordManager.cs index 5ca0732..59d85d7 100644 --- a/MCTG/Model/Managers/IPasswordManager.cs +++ b/MCTG/Model/Managers/IPasswordManager.cs @@ -6,10 +6,24 @@ using System.Threading.Tasks; namespace Model { + /// + /// Define how to manage passwords. + /// public interface IPasswordManager { + /// + /// Hash a plain text password. + /// + /// The plain password to hash. + /// The hashed password. public string HashPassword(string password); - public bool VerifyPassword(string hashedPassword,string password); + /// + /// Verify a plain text password with a hashed one. + /// + /// The hashed password. + /// The plain text password. + /// True is the password is correct, false otherwise. + public bool VerifyPassword(string hashedPassword,string password); } } diff --git a/MCTG/Model/Managers/IRecipeManager.cs b/MCTG/Model/Managers/IRecipeManager.cs index 093fbae..5a7fe22 100644 --- a/MCTG/Model/Managers/IRecipeManager.cs +++ b/MCTG/Model/Managers/IRecipeManager.cs @@ -6,16 +6,62 @@ using System.Threading.Tasks; namespace Model { + /// + /// Define how to manage recipes. + /// public interface IRecipeManager { + /// + /// Get or set the currently selected recipe. + /// Recipe? CurrentSelected { get; set; } + /// + /// Get all the recipe in the data. + /// + /// The RecipeCollection containing the recipes stored in the data. RecipeCollection GetAllRecipes(); + + /// + /// Get the recipe corresponding to the id. + /// + /// The id of the recipe we want. + /// The recipe corresponding to the id. Recipe GetRecipeFromId(int id); + + /// + /// Search in data the recipes containing this part of title. + /// + /// Search string. + /// The RecipeCollection of recipes corresponding to the search. RecipeCollection SearchRecipeByTitle(string title); + + /// + /// Get all the recipes created by the author. + /// + /// The author's mail. + /// The RecipeCollection of the recipe created by the author. RecipeCollection GetRecipeByAuthor(string authorMail); + + /// + /// Get an ordored list of the recipes sorted by the priority list. + /// + /// The priority list. + /// The RecipeCollection ordored by the priority list. RecipeCollection GetRecipesByPriorityOrder(IEnumerable priority); + + /// + /// Add a recipe to the data. + /// + /// The recipe to add. + /// Weither the adding succed or not. bool AddRecipeToData(Recipe recipe); + + /// + /// Modify the recipe with a new one in the data. + /// + /// The new recipe + /// Weither the modification succed or not. bool ModifyCurrentSelected(Recipe newRecipe); } } diff --git a/MCTG/Model/Managers/IUserManager.cs b/MCTG/Model/Managers/IUserManager.cs index 5babaf4..c4c7195 100644 --- a/MCTG/Model/Managers/IUserManager.cs +++ b/MCTG/Model/Managers/IUserManager.cs @@ -6,14 +6,52 @@ using System.Threading.Tasks; namespace Model { + /// + /// Define how to manage an user. + /// public interface IUserManager { + /// + /// Get the current connected user. Null if no user is connected. + /// User? CurrentConnected { get; } + + /// + /// Get the password manager used to hash passords. + /// IPasswordManager PasswordManager { get; } + /// + /// Get a collection of all users in the data. + /// + /// A collection of all user. ICollection GetAllUsers(); + + /// + /// Get an user by his email. + /// + /// The user's mail. + /// The user corresponding to the mail. User GetUserFromMail(string mail); - User CreateUser(string? name, string? surname, string mail, string password, string? profilePict); + + /// + /// Create a new user. The mail and the password are required. Other can be null. + ///
This function use the password manager to hash the plain text password. + ///
+ /// The user's mail address. + /// The user's plain text password. + /// The user's name. + /// The user's surname. + /// The user's profile picture. + /// A new user. + User CreateUser(string mail, string password, + string? name = null, string? surname = null, string? profilePict = null); + + /// + /// + /// + /// + /// bool AddUserToData(User user); bool ModifyCurrentConnected(User newUser); bool LogIn(string mail, string password);