merge's resolution not finish
continuous-integration/drone/push Build is failing Details

pull/48/head
Roxane ROSSETTO 2 years ago
commit 77984ad596

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Configurations>Debug;Release;CI</Configurations>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DataPersistence\DataPersistence.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project>

@ -3,22 +3,48 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ConsoleApp.Menu.Core;
using Model.Managers;
namespace ConsoleApp.Menu namespace ConsoleApp.Menu
{ {
internal class ConnectionMenu : Entry internal class ConnectionMenu : Entry
{ {
public ConnectionMenu() private MasterManager _masterMgr;
private bool _wrongInput = false;
public ConnectionMenu(MasterManager masterManager)
: base("Connection", : base("Connection",
new Entry.EntryStep("Username: ", typeof(string)), new Entry.EntryStep("Mail: ", typeof(string)),
new Entry.EntryStep("Password: ", typeof(string))) new Entry.EntryStep("Password: ", typeof(string), true))
{ } {
_masterMgr = masterManager;
}
public override void Display()
{
base.Display();
if (_wrongInput)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Wrong input...");
Console.ResetColor();
}
}
public override IMenu? Return() public override IMenu? Return()
{ {
string username = _selectList[0].Item.Input; string mail = _selectList[0].Item.Input;
string password = _selectList[1].Item.Input; string password = _selectList[1].Item.Input;
return new PlainText($"User: {username} connected with password: {password}");
if (!_masterMgr.Login(mail, password))
{
_wrongInput = true;
return this;
}
else
return null;
} }
} }
} }

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ConsoleApp.Menu namespace ConsoleApp.Menu.Core
{ {
internal abstract partial class Entry internal abstract partial class Entry
{ {
@ -25,6 +25,11 @@ namespace ConsoleApp.Menu
/// Contain the input gave by the menu. /// Contain the input gave by the menu.
/// </summary> /// </summary>
public string Input { get; internal set; } public string Input { get; internal set; }
/// <summary>
/// Define whether the input need to be hidden. Useful for password.
/// </summary>
public bool Hidden { get; private set; }
#endregion #endregion
#region Constructors #region Constructors
@ -33,11 +38,12 @@ namespace ConsoleApp.Menu
/// </summary> /// </summary>
/// <param name="description">The text generally placed before the input in the menu.</param> /// <param name="description">The text generally placed before the input in the menu.</param>
/// <param name="type">The type of the returned input.</param> /// <param name="type">The type of the returned input.</param>
public EntryStep(string description, Type type) public EntryStep(string description, Type type, bool hidden = false)
{ {
Description = description; Description = description;
Input = ""; Input = "";
_entryType = type; _entryType = type;
Hidden = hidden;
} }
#endregion #endregion

@ -3,8 +3,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ConsoleApp.Menu.Core;
namespace ConsoleApp.Menu namespace ConsoleApp.Menu.Core
{ {
/// <summary> /// <summary>
/// Define an Entry menu. /// Define an Entry menu.
@ -22,7 +23,8 @@ namespace ConsoleApp.Menu
/// </summary> /// </summary>
/// <param name="title">The title of this menu.</param> /// <param name="title">The title of this menu.</param>
/// <param name="entrySteps">All the entries of this menu.</param> /// <param name="entrySteps">All the entries of this menu.</param>
protected Entry(string title, params EntryStep[] entrySteps) : base(title) protected Entry(string title, params EntryStep[] entrySteps)
: base(title)
{ {
_steps = entrySteps.ToList(); _steps = entrySteps.ToList();
_allSelectors = ConvertEntryStepsInSelector(); _allSelectors = ConvertEntryStepsInSelector();
@ -95,6 +97,9 @@ namespace ConsoleApp.Menu
for (int i = 0; i < _selectList.Count; i++) for (int i = 0; i < _selectList.Count; i++)
{ {
if (CurrentLine == i) if (CurrentLine == i)
if (WriteMode)
_screenDisplay.Append($"W ");
else
_screenDisplay.Append($"> "); _screenDisplay.Append($"> ");
else else
_screenDisplay.Append($" "); _screenDisplay.Append($" ");

@ -5,7 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ConsoleApp.Menu namespace ConsoleApp.Menu.Core
{ {
/// <summary> /// <summary>
/// Define a console menu with element selection. /// Define a console menu with element selection.

@ -7,7 +7,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ConsoleApp.Menu namespace ConsoleApp.Menu.Core
{ {
/// <summary> /// <summary>
/// Define a selection menu. /// Define a selection menu.
@ -44,7 +44,7 @@ namespace ConsoleApp.Menu
{ {
_currentLine = value; _currentLine = value;
if (_currentLine <= 0) _currentLine = 0; if (_currentLine <= 0) _currentLine = 0;
else if (_currentLine >= _selectList.Count) _currentLine = _selectList.Count-1; else if (_currentLine >= _selectList.Count) _currentLine = _selectList.Count - 1;
} }
} }
@ -75,7 +75,7 @@ namespace ConsoleApp.Menu
/// </summary> /// </summary>
/// <param name="title">The title of the menu.</param> /// <param name="title">The title of the menu.</param>
/// <param name="selections">The selections of the menu.</param> /// <param name="selections">The selections of the menu.</param>
protected Menu(string title, params Selector<T>[] selections ) : this(title) protected Menu(string title, params Selector<T>[] selections) : this(title)
{ {
if (selections == null || selections.Length == 0) if (selections == null || selections.Length == 0)
{ {

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ConsoleApp.Menu namespace ConsoleApp.Menu.Core
{ {
/// <summary> /// <summary>
/// Define a Plain text menu. /// Define a Plain text menu.

@ -7,7 +7,7 @@ using System.Reflection.Emit;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ConsoleApp.Menu namespace ConsoleApp.Menu.Core
{ {
/// <summary> /// <summary>
/// The selector of a menu. /// The selector of a menu.
@ -22,7 +22,8 @@ namespace ConsoleApp.Menu
/// <summary> /// <summary>
/// The string that are displayed on the menu. /// The string that are displayed on the menu.
/// </summary> /// </summary>
public string Line { public string Line
{
get => _line; get => _line;
private set private set
{ {
@ -57,7 +58,7 @@ namespace ConsoleApp.Menu
{ {
if (other == null) return false; if (other == null) return false;
if (other == this) return true; if (other == this) return true;
return other.Line.Equals(this.Line); return other.Line.Equals(Line);
} }
public override bool Equals(object? obj) public override bool Equals(object? obj)

@ -5,6 +5,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ConsoleApp.Menu.Core;
using Model.Managers;
namespace ConsoleApp.Menu namespace ConsoleApp.Menu
{ {
@ -13,12 +15,26 @@ namespace ConsoleApp.Menu
/// </summary> /// </summary>
internal class MainMenu : Menu<IMenu> internal class MainMenu : Menu<IMenu>
{ {
public MainMenu(DataManager dataMgr) public MainMenu(MasterManager masterManager)
: base("Main menu", : base("Main menu")
new Selector<IMenu>( {
new SearcherRecipe(new RecipeCollection("search", dataMgr.Data[nameof(Recipe)].Cast<Recipe>().ToArray())), "Recipe search"), _allSelectors.Add(new Selector<IMenu>(
new Selector<IMenu>( new SearcherRecipe(masterManager.DataMgr.GetRecipes("search")), "Recipe search"));
new ConnectionMenu(), "Connection"))
{ } _allSelectors.Add(
new Selector<IMenu>(new ConnectionMenu(masterManager), "Connection"));
_allSelectors.Add(
new Selector<IMenu>(new ProfileMenu(masterManager), "User profile"));
}
protected override List<Selector<IMenu>> SearchInSelection()
{
List<Selector<IMenu>> selectors = base.SearchInSelection();
if (MasterManager.CurrentConnectedUser == null)
return selectors.Except(selectors.Where(s => s.Line == "User profile")).ToList();
else
return selectors.Except(selectors.Where(s => s.Line == "Connection")).ToList();
}
} }
} }

@ -0,0 +1,31 @@
using ConsoleApp.Menu.Core;
using Model.Managers;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp.Menu
{
internal class ProfileMenu : Menu<IMenu>
{
public ProfileMenu(MasterManager masterManager)
: base("Profile")
{
_allSelectors.Add(new Selector<IMenu>(
new PlainText($"\nUser: {MasterManager.CurrentConnectedUser}\n\n"
+ $"\tMail: {MasterManager.CurrentConnectedUser?.Mail}\n"
+ $"\tMail: {MasterManager.CurrentConnectedUser?.Name}\n"
+ $"\tMail: {MasterManager.CurrentConnectedUser?.Surname}\n"),
"My informations"));
_allSelectors.Add(new Selector<IMenu>(
new SearcherRecipe(new RecipeCollection("My recipes",
masterManager.DataMgr.GetRecipes().Where(r => r.AuthorMail == MasterManager.CurrentConnectedUser?.Mail).ToArray())),
"My recipes"));
}
}
}

@ -4,7 +4,7 @@ using System.Linq;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ConsoleApp.Menu.Core;
using Model; using Model;
namespace ConsoleApp.Menu namespace ConsoleApp.Menu

@ -6,6 +6,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ConsoleApp.Menu.Core;
using Model.Managers;
namespace ConsoleApp namespace ConsoleApp
{ {
@ -18,33 +20,33 @@ namespace ConsoleApp
/// <summary> /// <summary>
/// The manager that contains usefull data taken from the model. /// The manager that contains usefull data taken from the model.
/// </summary> /// </summary>
public DataManager DataManager { get; private set; } public MasterManager MasterMgr { get; private set; }
/// <summary> /// <summary>
/// Each menu called are push in this stack. Then, to return back, we pop this stack to retrive the previous menu. /// Each menu called are push in this stack. Then, to return back, we pop this stack to retrive the previous menu.
/// </summary> /// </summary>
public Stack<Menu.IMenu> MenuCallStack { get; set; } public Stack<IMenu> MenuCallStack { get; set; }
#endregion #endregion
#region Constructors #region Constructors
/// <summary> /// <summary>
/// Constructor of the MenuManager class. This constructor allows you to give the first menu of the call stack, wich is usefull for testing. /// Constructor of the MenuManager class. This constructor allows you to give the first menu of the call stack, wich is usefull for testing.
/// </summary> /// </summary>
/// <param name="dataManager">The data manager needed by the menus inside.</param> /// <param name="masterManager">The data manager needed by the menus inside.</param>
/// <param name="firstMenu">The starting menu, the first that will be push on the call stack.</param> /// <param name="firstMenu">The starting menu, the first that will be push on the call stack.</param>
public MenuManager(DataManager dataManager, Menu.IMenu firstMenu) public MenuManager(MasterManager masterManager, IMenu firstMenu)
{ {
DataManager = dataManager; MasterMgr = masterManager;
MenuCallStack = new Stack<Menu.IMenu>(); MenuCallStack = new Stack<IMenu>();
MenuCallStack.Push(firstMenu); MenuCallStack.Push(firstMenu);
} }
/// <summary> /// <summary>
/// Constructor of the MenuManager class. /// Constructor of the MenuManager class.
/// </summary> /// </summary>
/// <param name="dataManager">The data manager needed by the menus inside.</param> /// <param name="masterManager">The data manager needed by the menus inside.</param>
public MenuManager(DataManager dataManager) : this(dataManager, new MainMenu(dataManager)) public MenuManager(MasterManager masterManager) : this(masterManager, new MainMenu(masterManager))
{ } { }
#endregion #endregion
@ -55,7 +57,7 @@ namespace ConsoleApp
public void Loop() public void Loop()
{ {
ConsoleKeyInfo cki; ConsoleKeyInfo cki;
Menu.IMenu menuOnHead; IMenu menuOnHead;
do do
{ {
menuOnHead = MenuCallStack.Peek(); menuOnHead = MenuCallStack.Peek();
@ -72,7 +74,7 @@ namespace ConsoleApp
menuOnHead.SelectPrevious(); menuOnHead.SelectPrevious();
break; break;
case ConsoleKey.Enter: case ConsoleKey.Enter:
Menu.IMenu? retMenu = menuOnHead.Return(); IMenu? retMenu = menuOnHead.Return();
if (retMenu is null) MenuCallStack.Pop(); if (retMenu is null) MenuCallStack.Pop();
else MenuCallStack.Push(retMenu); else MenuCallStack.Push(retMenu);
break; break;

@ -1,48 +1,26 @@
 using ConsoleApp;
using ConsoleApp;
using Model; using Model;
using ConsoleApp.Menu; using ConsoleApp.Menu;
using DataPersistence; using DataPersistence;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Model.Managers;
Console.WriteLine("Hello, World!\n\n"); Console.WriteLine("Hello, World!\n\n");
MasterManager masterMgr = new MasterManager(new Stubs());
//_masterMgr masterMgr = new _masterMgr(new DataContractXML());
//_masterMgr masterMgr = new _masterMgr(new DataContractJSON());
// TESTS: masterMgr.DataMgr.Serializer = new DataContractXML();
DataManager dataMgr = new DataManager(new Stubs()); //masterMgr.Serializer = new DataContractJSON();
//DataManager dataMgr = new DataManager(new DataContractXML());
//DataManager dataMgr = new DataManager(new DataContractJSON());
dataMgr.Serializer = new DataContractXML();
//dataMgr.Serializer = new DataContractJSON();
// /!\ here is an absolute path I put for testing purpose. It will only work on my computer so don't forget to change it whene you test.
//dataMgr.Export(rc[2], "C:\\Users\\alex6\\Downloads\\recipe2.json");
//dataMgr.Import<Recipe>("C:\\Users\\alex6\\Downloads\\recipe2.json");
PasswordManager passwordManager = new PasswordManager(); masterMgr.DataMgr.Save();
//RecipeCollection rc = new RecipeCollection("All recipes", dataMgr.Data[nameof(Recipe)].Cast<Recipe>().ToArray());
User user = dataMgr.Data[nameof(User)].Cast<User>().Last();
//rc[0].AddReview(new Review(user, 1, "bonne recette !1"));
//rc[0].AddReview(new Review(user, 1, "bonne recette !2"));
//rc[0].AddReview(new Review(user, 4, "bonne recette !3"));
//rc[0].AddReview(new Review(user, 5, "bonne recette !4"));
//rc[0].AddReview(new Review(user, 3, "bonne recette !5"));
//rc[0].AddReview(new Review(user, 2, "bonne recette !6"));
//rc[0].AddReview(new Review(user, 2, "peut etre pas ducoup !"));
//rc[1].AddReview(new Review(user, 2, "Mais celle-ci oui !"));
dataMgr.Save();
MenuManager menuMgr = new MenuManager(dataMgr);
MenuManager menuMgr = new MenuManager(masterMgr);
menuMgr.Loop(); menuMgr.Loop();
Console.WriteLine(passwordManager.VerifyPassword(user.Password, "pamigos"));
Console.ReadKey(); Console.ReadKey();

@ -38,7 +38,9 @@ namespace DataPersistence
{ {
typeof(Recipe), typeof(Recipe),
typeof(Review), typeof(Review),
typeof(User) typeof(User),
typeof(Ingredient),
typeof(Quantity)
} }
}; };
else else

@ -46,7 +46,9 @@ namespace DataPersistence
{ {
typeof(Recipe), typeof(Recipe),
typeof(Review), typeof(Review),
typeof(User) typeof(User),
typeof(Ingredient),
typeof(Quantity)
}, },
PreserveObjectReferences = true PreserveObjectReferences = true
}; };

@ -14,7 +14,6 @@ namespace DataPersistence
{ {
public Dictionary<string, List<object>> Load() public Dictionary<string, List<object>> Load()
{ {
Dictionary<string, List<object>> data = new Dictionary<string, List<object>> Dictionary<string, List<object>> data = new Dictionary<string, List<object>>
{ {
{ {
@ -24,17 +23,22 @@ namespace DataPersistence
{ {
new Recipe( new Recipe(
title: "Cookies classiques", title: "Cookies classiques",
id: 50,
authorMail: "admin@mctg.fr",
picture : "room_service_icon.png", picture : "room_service_icon.png",
id: null, ingredients: new List<Ingredient>(new[]
{
new Ingredient("Patates", new Quantity(23, Unit.unit)),
new Ingredient("Farine", new Quantity(23, Unit.G))
}),
preparationSteps: new[] preparationSteps: new[]
{ {
new PreparationStep(1, "Faire cuire."), new PreparationStep(1, "Faire cuire."),
new PreparationStep(2, "Manger.") new PreparationStep(2, "Manger.")
}), }),
new Recipe( new Recipe(
title: "Cookies au chocolat", authorMail: "admin@mctg.fr",
picture : "", title: "Cookies au chocolat", id: null,
id: null,
preparationSteps: new[] preparationSteps: new[]
{ {
new PreparationStep(1, "Moulinez la pâte."), new PreparationStep(1, "Moulinez la pâte."),
@ -42,9 +46,8 @@ namespace DataPersistence
new PreparationStep(3, "Sortir du four et mettre dans un plat.") new PreparationStep(3, "Sortir du four et mettre dans un plat.")
}), }),
new Recipe( new Recipe(
title: "Gateau nature", title: "Gateau nature", id: null,
picture : "dotnet_bot.svg", authorMail: "admin@mctg.fr",
id: null,
preparationSteps: new[] preparationSteps: new[]
{ {
new PreparationStep(1, "Achetez les ingrédients."), new PreparationStep(1, "Achetez les ingrédients."),
@ -52,29 +55,30 @@ namespace DataPersistence
new PreparationStep(3, "Pleurez.") new PreparationStep(3, "Pleurez.")
}), }),
new Recipe( new Recipe(
title: "Gateau nature", title: "Gateau au pommes", id: null,
picture : "dotnet_bot.svg", authorMail: "admin@mctg.fr",
id: null,
preparationSteps: new[] preparationSteps: new[]
{ {
new PreparationStep(1, "Achetez les ingrédients."), new PreparationStep(1, "Achetez les légumes."),
new PreparationStep(2, "Préparez le matériel. Ustensiles et tout."), new PreparationStep(2, "Préparez le plat. Ustensiles et préchauffez le four."),
new PreparationStep(3, "Pleurez.") 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( new Recipe(
title: "Gateau nature", title: "Gateau au chocolat", id: null,
picture : "dotnet_bot.svg", authorMail: "pedrosamigos@hotmail.com",
id: null,
preparationSteps: new[] preparationSteps: new[]
{ {
new PreparationStep(1, "Achetez les ingrédients."), new PreparationStep(1, "Ajouter les oeufs."),
new PreparationStep(2, "Préparez le matériel. Ustensiles et tout."), new PreparationStep(2, "Ajouter la farine."),
new PreparationStep(3, "Pleurez.") 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( new Recipe(
title: "Dinde au jambon", title: "Dinde au jambon",
picture : "",
id: null, id: null,
authorMail: "pedrosamigos@hotmail.com",
preparationSteps: new[] preparationSteps: new[]
{ {
new PreparationStep(1, "Faire une cuisson bien sec de la dinde à la poêle"), new PreparationStep(1, "Faire une cuisson bien sec de la dinde à la poêle"),
@ -84,18 +88,21 @@ namespace DataPersistence
new PreparationStep(5, "Présentez sur un plat la dinde et le jambon : Miam !") new PreparationStep(5, "Présentez sur un plat la dinde et le jambon : Miam !")
}), }),
new Recipe( new Recipe(
title: "Gateau nature", title: "Poulet au curry", id: null,
picture : "dotnet_bot.svg", authorMail: "pedrosamigos@hotmail.com",
id: null,
preparationSteps: new[] preparationSteps: new[]
{ {
new PreparationStep(1, "Achetez les ingrédients."), new PreparationStep(1, "Trouvez des épices de curry."),
new PreparationStep(2, "Préparez le matériel. Ustensiles et tout."), new PreparationStep(2, "Trouvez maintenant du poulet."),
new PreparationStep(3, "Pleurez.") 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 #endregion
}, },
{ {
#region Data: User #region Data: User
nameof(User), nameof(User),

@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Ingredient
{
internal class Ingredient
{
}
}

@ -5,7 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace DataPersistence namespace Model
{ {
/// <summary> /// <summary>
/// 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. /// 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.
@ -76,6 +76,30 @@ namespace DataPersistence
public void Export<T>(T obj, string pathToExport) public void Export<T>(T obj, string pathToExport)
where T : class where T : class
=> Serializer.Export<T>(obj, pathToExport); => Serializer.Export<T>(obj, pathToExport);
/// <summary>
/// Get all the recipe from the data.
/// </summary>
/// <param name="rcTitle">The title to give for the Recipe Collection</param>
/// <returns>A RecipeCollection that contain all the recipe in the data.</returns>
public RecipeCollection GetRecipes(string rcTitle = "default")
=> new RecipeCollection(rcTitle, Data[nameof(Recipe)].Cast<Recipe>().ToArray());
/// <summary>
/// Get all the Users from the data.
/// </summary>
/// <returns>A list of all Users.</returns>
public List<User> GetUsers()
=> new List<User>(Data[nameof(User)].Cast<User>());
/// <summary>
/// Get a list of an item in the data.
/// </summary>
/// <typeparam name="T">The type of the item</typeparam>
/// <returns>The list of all the item found in the data.</returns>
public ICollection<T> GetFromData<T>() where T : class
=> new List<T>(Data[typeof(T).Name].Cast<T>());
#endregion #endregion
} }
} }

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace DataPersistence namespace Model
{ {
/// <summary> /// <summary>
/// Interface that define the methods of a data serializer. /// Interface that define the methods of a data serializer.

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Model.Managers
{
public class MasterManager
{
public static User? CurrentConnectedUser;
public static RecipeCollection? Recipes;
public static List<User>? Users;
public DataManager DataMgr { get; private set; }
public MasterManager(IDataManager dataManager)
{
DataMgr = new DataManager(dataManager);
CurrentConnectedUser = null;
Users = DataMgr.GetUsers();
}
public bool Login(string mail, string password)
{
if (Users is null || Users.Count == 0)
throw new ArgumentNullException("There is no users registred.");
User? user = Users.Find(u => u.Mail == mail);
if (user is null || !user.psswMgr.VerifyPassword(user.Password, password))
return false;
CurrentConnectedUser = user;
return true;
}
public bool Logout()
{
if (CurrentConnectedUser is null)
return false;
CurrentConnectedUser = null;
return true;
}
public bool Register(User newuser)
{
try
{
User user = newuser;
DataMgr.Data[nameof(User)].Add(user);
Users = DataMgr.GetUsers();
}
catch (ArgumentException e)
{
Debug.WriteLine(e.Message);
return false;
}
return true;
}
public void AddRecipe(Recipe recipe)
{
DataMgr.Data[nameof(Recipe)].Add(recipe);
Recipes = DataMgr.GetRecipes();
}
}
}

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
[DataContract(Name = "ingredient")]
public class Ingredient
{
#region Attributes
[DataMember(Name = "id")]
private string _name = "";
[DataMember(Name = "quantity")]
private Quantity _quantity = new Quantity(1, Unit.unit);
#endregion
#region Properties
/// <summary>
/// Property of the Ingredient's attribute _name. It raises an ArgumentNullException to prevent a nullable field.
/// </summary>
public string Name
{
get => _name;
set
{
if (string.IsNullOrEmpty(value))
{
throw new ArgumentNullException("Impossible de ne pas avoir de nom pour l'ingrédient");
}
_name = value;
}
}
/// <summary>
/// Property of the Ingredient's attribute Quantity.
/// </summary>
public Quantity QuantityI
{
get => _quantity;
set => _quantity = value;
}
public bool Equals(Ingredient? other)
{
if (other == null) { return false; }
if (this == other) { return true; }
return Name.Equals(other.Name);
}
#endregion
#region Constructor
public Ingredient(string name, Quantity quantity)
{
Name = name;
QuantityI = quantity;
}
#endregion
public override string ToString()
{
return $"{Name} ({QuantityI})";
}
}
}

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
/// <summary>
/// Quantity is a class which is associate to Ingedients. It represents the _quantity of every ingredient with an enum
/// to indicate the unit of the _quantity.
/// </summary>
[DataContract(Name = "quantity")]
public class Quantity
{
#region Attributes
/// <summary>
/// get the quatity of ingredient
/// </summary>
[DataMember(Name = "digit")]
private int number;
/// <summary>
/// have the Unit enum of the _quantity of ingredient
/// </summary>
[DataMember(Name = "unit")]
private Unit unit;
#endregion
#region Properties
/// <summary>
/// Represents the _quantity in digits. The null value raise an argumentException.
/// </summary>
public int Number
{
get { return number; }
set
{
if (value < 0)
{
throw new ArgumentException("Si la quantité est inférieur à 0, enlever l'ingrédient!");
}
number = value;
}
}
public Unit UnitQ
{
get => unit;
set => unit = value;
}
#endregion
#region Constructor
/// <summary>
/// Constructor of Quantity
/// </summary>
/// <param _name="number"></param>
/// <param _name="unit"></param>
public Quantity(int number, Unit unit)
{
Number = number;
UnitQ = unit;
}
#endregion
public override string ToString()
{
return $"{Number}{UnitQ}";
}
}
}

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
/// <summary>
/// Unit is an Enum that represents the units of quantities
/// <list type="Unit, kG, mG, G, L, cL, mL"/>
/// </summary>
public enum Unit
{ unit, kG, mG, G, L, cL, mL };
}

@ -46,8 +46,8 @@ namespace Model
/// <summary> /// <summary>
/// Construct a new step of preparation. /// Construct a new step of preparation.
/// </summary> /// </summary>
/// <param name="order">The number of the order in preparation</param> /// <param _name="order">The number of the order in preparation</param>
/// <param name="description">The description of the task</param> /// <param _name="description">The description of the task</param>
public PreparationStep(int order, string description = "") public PreparationStep(int order, string description = "")
{ {
Order = order; Order = order;

@ -34,6 +34,12 @@ namespace Model
[DataMember(Name = "reviews")] [DataMember(Name = "reviews")]
public List<Review> Reviews { get; private set; } public List<Review> Reviews { get; private set; }
/// <summary>
/// AuthorMail's mail of the recipe.
/// </summary>
[DataMember(Name = "authorMail")]
public string? AuthorMail { get; private set; }
/// <summary> /// <summary>
/// The Title of the recipe. <br/> /// The Title of the recipe. <br/>
/// Set to "No title." when the value passed is null, empty or contain white spaces. /// Set to "No title." when the value passed is null, empty or contain white spaces.
@ -54,7 +60,7 @@ namespace Model
/// The image of the recipe. <br/> /// The image of the recipe. <br/>
/// Set to "room_service_icon.png" when the value passed is null, empty or contain white space. /// Set to "room_service_icon.png" when the value passed is null, empty or contain white space.
/// </summary> /// </summary>
public string Image public string? Image
{ {
get => _image; get => _image;
set set
@ -65,6 +71,12 @@ namespace Model
} }
} }
/// The list of ingredients.
/// </summary>
[DataMember(Name = "ingredient")]
public List<Ingredient> Ingredients { get; set; }
/// <summary> /// <summary>
/// The steps of the preparation. See: <see cref="PreparationStep"/>. /// The steps of the preparation. See: <see cref="PreparationStep"/>.
/// </summary> /// </summary>
@ -76,17 +88,23 @@ namespace Model
/// <summary> /// <summary>
/// Construct a new recipe. /// Construct a new recipe.
/// </summary> /// </summary>
/// <param name="title">The title of the recipe</param> /// <param _name="title">The title of the recipe</param>
/// <param name="id">The id of the recipe. If not given, get a new id.</param> /// <param _name="id">The id of the recipe. If not given, get a new id.</param>
/// <param name="preparationSteps">The steps of the preparation of the meal</param> /// <param _name="authorMail">The name of the user that create this recipe.</param>
public Recipe(string title, string picture, int? id, /// <param _name="picture"> The image that represent the recipe</param>
List<Review> reviews, /// <param _name="reviews">Thr list of reviews.</param>
/// <param _name="ingredients">Thr list of ingredients.</param>
/// <param _name="preparationSteps">The steps of the preparation of the meal</param>
public Recipe(string title, int? id, string? authorMail, string? picture,
List<Review> reviews, List<Ingredient> ingredients,
params PreparationStep[] preparationSteps) params PreparationStep[] preparationSteps)
{ {
Title = title; Title = title;
Image = picture; Image = picture;
PreparationSteps = new List<PreparationStep>(preparationSteps); PreparationSteps = new List<PreparationStep>(preparationSteps);
Ingredients = ingredients;
Reviews = reviews; Reviews = reviews;
AuthorMail = authorMail;
if (id == null) if (id == null)
{ {
@ -98,42 +116,84 @@ namespace Model
else Id = (int)id; else Id = (int)id;
} }
/// <summary> /// <summary>
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/> /// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
/// </summary> /// </summary>
/// <param name="title">The title of the recipe.</param> /// <param _name="title">The title of the recipe.</param>
public Recipe(string title, string picture) /// <param _name="preparationSteps">The steps of the preparation of the meal.</param>
: this(title, picture, null, new List<Review>()) public Recipe(string title, params PreparationStep[] preparationSteps)
: this(title, null, null,null, new List<Review>(), new List<Ingredient>(), preparationSteps)
{ {
} }
/// <summary> /// <summary>
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/> /// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
/// </summary> /// </summary>
/// <param name="title">The title of the recipe.</param>
/// <param name="preparationSteps">The steps of the preparation of the meal.</param> /// <param _name="title">The title of the recipe.</param>
public Recipe(string title, params PreparationStep[] preparationSteps) /// <param _name="id">The id of the recipe. If not given, get a new id.</param>
: this(title, picture : null, null, new List<Review>(), preparationSteps) /// <param _name="picture">Image that reppresent the recipe.</param>
/// <param _name="preparationSteps">The steps of the preparation of the meal.</param>
public Recipe(string title, int? id, string picture, params PreparationStep[] preparationSteps)
: this(title, id, null, picture, new List<Review>(), new List<Ingredient>(), preparationSteps)
{
}
/// <param _name="title">The title of the recipe.</param>
/// <param _name="id">The id of the recipe. If not given, get a new id.</param>
/// <param _name="preparationSteps">The steps of the preparation of the meal.</param>
public Recipe(string title, int? id, params PreparationStep[] preparationSteps)
: this(title, id, null, null, new List<Review>(), new List<Ingredient>(), preparationSteps)
{
}
/// <summary>
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
/// </summary>
/// <param _name="title">The title of the recipe.</param>
/// <param _name="id">The id of the recipe. If not given, get a new id.</param>
/// <param _name="ingredients">Thr list of ingredients.</param>
/// <param _name="preparationSteps">The steps of the preparation of the meal.</param>
public Recipe(string title, int? id, List<Ingredient> ingredients,
params PreparationStep[] preparationSteps)
: this(title, id, null, null, new List<Review>(), ingredients, preparationSteps)
{ {
} }
/// <summary> /// <summary>
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/> /// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
/// </summary> /// </summary>
/// <param name="title">The title of the recipe.</param> /// <param _name="title">The title of the recipe.</param>
/// <param name="id">The id of the recipe. If not given, get a new id.</param> /// <param _name="id">The id of the recipe. If not given, get a new id.</param>
/// <param name="preparationSteps">The steps of the preparation of the meal.</param> /// <param _name="authorMail">Mail of the user that create the recipe</param>
public Recipe(string title, string picture, int? id, params PreparationStep[] preparationSteps) /// <param _name="ingredients">List of ingredients that compose the recipe. </param>
: this(title, picture, id, new List<Review>(), preparationSteps) /// <param _name="preparationSteps">The steps of the preparation of the meal.</param>
public Recipe(string title, int? id, string? authorMail, List<Ingredient> ingredients, params PreparationStep[] preparationSteps)
: this(title, id, authorMail, null, new List<Review>(), ingredients, preparationSteps)
{ {
} }
/// <summary>
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
/// </summary>
/// <param _name="title">The title of the recipe.</param>
/// <param _name="id">The id of the recipe. If not given, get a new id.</param>
/// <param _name="authorMail">Mail of the user that create the recipe</param>
/// <param _name="preparationSteps">The steps of the preparation of the meal.</param>
public Recipe(string title, int? id, string? authorMail, params PreparationStep[] preparationSteps)
: this(title, id, authorMail, null, new List<Review>(), new List<Ingredient>(), preparationSteps)
{
}
#endregion #endregion
#region Methods #region Methods
/// <summary> /// <summary>
/// Add a review for the recipe. /// Add a review for the recipe.
/// </summary> /// </summary>
/// <param name="review">The new review to add.</param> /// <param _name="review">The new review to add.</param>
public void AddReview(Review review) public void AddReview(Review review)
=> Reviews.Add(review); => Reviews.Add(review);
@ -151,6 +211,22 @@ namespace Model
return sb.ToString(); return sb.ToString();
} }
/// <summary>
/// Concatenate the list of ingredients in a single string
/// </summary>
/// <returns>The list of ingredients in string format</returns>
private string ConcatIngredients()
{
StringBuilder sb = new StringBuilder();
foreach (Ingredient ingredient in Ingredients)
{
sb.Append("\t- " + ingredient.ToString() + "\n");
}
return sb.ToString();
}
public virtual bool Equals(Recipe? other) public virtual bool Equals(Recipe? other)
{ {
if (other == null) return false; if (other == null) return false;
@ -178,10 +254,14 @@ namespace Model
sb.AppendFormat("\t* {0}\n", ps.ToString()); sb.AppendFormat("\t* {0}\n", ps.ToString());
} }
sb.AppendLine(); sb.AppendLine();
sb.AppendLine(ConcatIngredients());
sb.AppendLine();
foreach (Review review in Reviews) foreach (Review review in Reviews)
{ {
sb.AppendLine(review.ToString()); sb.AppendLine(review.ToString());
} }
sb.AppendLine();
sb.AppendLine($"Posted by: {AuthorMail?.ToString()}");
return sb.ToString(); return sb.ToString();
} }
#endregion #endregion

@ -38,8 +38,8 @@ namespace Model
/// <summary> /// <summary>
/// Construct a new collection of _recipes. /// Construct a new collection of _recipes.
/// </summary> /// </summary>
/// <param name="description">A short description of what this list will contain</param> /// <param _name="description">A short description of what this list will contain</param>
/// <param name="recipes">Recipes to add in this new collection</param> /// <param _name="recipes">Recipes to add in this new collection</param>
public RecipeCollection(string description, params Recipe[] recipes) public RecipeCollection(string description, params Recipe[] recipes)
: base(recipes) : base(recipes)
{ {
@ -51,7 +51,7 @@ namespace Model
/// <summary> /// <summary>
/// Find a recipe in this list by giving the id. /// Find a recipe in this list by giving the id.
/// </summary> /// </summary>
/// <param name="id">The id of the list we are looking for</param> /// <param _name="id">The id of the list we are looking for</param>
/// <returns>The recipe of the id given</returns> /// <returns>The recipe of the id given</returns>
/// <exception cref="ArgumentException"/> /// <exception cref="ArgumentException"/>
public Recipe? GetRecipeById(int id) public Recipe? GetRecipeById(int id)
@ -62,9 +62,9 @@ namespace Model
} }
/// <summary> /// <summary>
/// Utility to find a recipe by his name. /// Utility to find a recipe by his _name.
/// </summary> /// </summary>
/// <param name="str">The string for the search</param> /// <param _name="str">The string for the search</param>
/// <returns>A collection of Recipe where their Title contain the string.</returns> /// <returns>A collection of Recipe where their Title contain the string.</returns>
public RecipeCollection ResearchByName(string str) public RecipeCollection ResearchByName(string str)
{ {

@ -1,4 +1,5 @@
using System; using Model.Managers;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.Serialization; using System.Runtime.Serialization;
@ -21,8 +22,8 @@ namespace Model
[DataMember(Name = "id")] [DataMember(Name = "id")]
public int Id { get; init; } public int Id { get; init; }
[DataMember(Name = "user")] [DataMember(Name = "authorMail")]
public User Author { get; private set; } public string AuthorMail { get; private set; }
public int Stars public int Stars
{ {
@ -44,7 +45,7 @@ namespace Model
} }
} }
public Review(User author, int? id, int stars, string content) public Review(string authorMail, int? id, int stars, string content)
{ {
if (id == null) if (id == null)
{ {
@ -55,24 +56,28 @@ namespace Model
} }
else Id = (int)id; else Id = (int)id;
Author = author; AuthorMail = authorMail;
Stars = stars; Stars = stars;
Content = content; Content = content;
} }
public Review(User author, int stars, string content) public Review(string authorMail, int stars, string content)
: this(author, null, stars, content) : this(authorMail, null, stars, content)
{ {
} }
public Review(int stars, string content) public Review(int stars, string content)
: this(new User(), null, stars, content) : this("admin@mctg.fr", null, stars, content)
{ {
} }
public override string ToString() public override string ToString()
{ {
return $"{Author.Name} {Author.Surname}: [ {Stars} stars ]\n{Content}"; User? user = MasterManager.Users?.Find(u => u.Mail == AuthorMail);
if (user is null)
return $"{AuthorMail}: [ {Stars} stars ]\n{Content}";
return $"{user.Name} {user.Surname}: [ {Stars} stars ]\n{Content}";
} }
public bool Equals(Review? other) public bool Equals(Review? other)

@ -13,7 +13,7 @@ using System.ComponentModel;
namespace Model namespace Model
{ {
/// <summary> /// <summary>
/// A user is an entity with a name, a surname, mail, profilePict and a list of priority. /// A user is an entity with a _name, a surname, mail, profilePict and a list of priority.
/// This user can login with an Id and a password /// This user can login with an Id and a password
/// </summary> /// </summary>
[DataContract(Name = "user")] [DataContract(Name = "user")]
@ -146,7 +146,6 @@ namespace Model
#endregion #endregion
#region Constructors #region Constructors
/// <summary> /// <summary>
@ -154,7 +153,9 @@ namespace Model
/// </summary> /// </summary>
/// <param name="name">The name of the user</param> /// <param name="name">The name of the user</param>
/// <param name="surname">The surname of the user</param> /// <param name="surname">The surname of the user</param>
/// <param name="mail">The user needs an email to login. </param> /// <param name="mail">The user needs an email to login.</param>
/// <param name="password">The password of the new user.</param>
/// <param name="passwordManager">The password manager to manage the user password.</param>
public User(string name, string surname, string mail, string password, IPasswordManager passwordManager ) public User(string name, string surname, string mail, string password, IPasswordManager passwordManager )
{ {
Name = name; Name = name;
@ -171,19 +172,28 @@ namespace Model
ProfilPict = picture; ProfilPict = picture;
} }
/// <summary>
/// <inheritdoc cref="User.User"/>
/// </summary>
public User(string name, string surname, string mail, string password) public User(string name, string surname, string mail, string password)
: this(name, surname,mail, password, new PasswordManager()) : this(name, surname,mail, password, new PasswordManager())
{ {
} }
/// <summary>
/// <inheritdoc cref="User.User"/>
/// </summary>
public User() public User()
: this("John", "Doe", "truc@gmail.com", "mdp") : this("John", "Doe", "truc@gmail.com", "mdp")
{ {
} }
/// <summary>
/// <inheritdoc cref="User.User"/>
/// </summary>
public User (User user) public User (User user)
{ {
Name = user.Name; Name = user.Name;
@ -197,8 +207,6 @@ namespace Model
#endregion #endregion
} }
} }

@ -1,4 +1,3 @@

Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.5.33516.290 VisualStudioVersion = 17.5.33516.290

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
namespace Model_UnitTests
{
public class Ingredient_UT
{
public void TestConstructIngredient()
{
Quantity quantity = new Quantity(200, Unit.mL);
Ingredient patate = new Ingredient("Patate", quantity);
Assert.Equal("Patate", patate.Name);
}
}
}

@ -1,31 +0,0 @@
<<<<<<< HEAD
<Project Sdk="Microsoft.NET.Sdk">
=======
<Project Sdk="Microsoft.NET.Sdk">
>>>>>>> feature/18-model-user
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<Configurations>Debug;Release;CI</Configurations>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Model\Model.csproj" />
<ProjectReference Include="..\..\DataPersistence\DataPersistence.csproj" />
</ItemGroup>
</Project>

@ -24,3 +24,4 @@
<ProjectReference Include="..\..\DataPersistence\DataPersistence.csproj" /> <ProjectReference Include="..\..\DataPersistence\DataPersistence.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -27,9 +27,7 @@ namespace Views
public App() public App()
{ {
CurrentUser = DataMgr.Data[nameof(User)].Cast<User>().Last(); CurrentUser = DataMgr.Data[nameof(User)].Cast<User>().Last();
AllRecipes = DataMgr.Data[nameof(RecipeCollection)]
.Cast<RecipeCollection>()
.ToArray();
InitializeComponent(); InitializeComponent();
// Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) => // Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) =>

Loading…
Cancel
Save