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.Text;
using System.Threading.Tasks;
using ConsoleApp.Menu.Core;
using Model.Managers;
namespace ConsoleApp.Menu
{
internal class ConnectionMenu : Entry
{
public ConnectionMenu()
private MasterManager _masterMgr;
private bool _wrongInput = false;
public ConnectionMenu(MasterManager masterManager)
: base("Connection",
new Entry.EntryStep("Username: ", typeof(string)),
new Entry.EntryStep("Password: ", typeof(string)))
{ }
new Entry.EntryStep("Mail: ", 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()
{
string username = _selectList[0].Item.Input;
string mail = _selectList[0].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.Threading.Tasks;
namespace ConsoleApp.Menu
namespace ConsoleApp.Menu.Core
{
internal abstract partial class Entry
{
@ -25,6 +25,11 @@ namespace ConsoleApp.Menu
/// Contain the input gave by the menu.
/// </summary>
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
#region Constructors
@ -33,11 +38,12 @@ namespace ConsoleApp.Menu
/// </summary>
/// <param name="description">The text generally placed before the input in the menu.</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;
Input = "";
_entryType = type;
Hidden = hidden;
}
#endregion

@ -3,8 +3,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleApp.Menu.Core;
namespace ConsoleApp.Menu
namespace ConsoleApp.Menu.Core
{
/// <summary>
/// Define an Entry menu.
@ -22,7 +23,8 @@ namespace ConsoleApp.Menu
/// </summary>
/// <param name="title">The title 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();
_allSelectors = ConvertEntryStepsInSelector();
@ -95,6 +97,9 @@ namespace ConsoleApp.Menu
for (int i = 0; i < _selectList.Count; i++)
{
if (CurrentLine == i)
if (WriteMode)
_screenDisplay.Append($"W ");
else
_screenDisplay.Append($"> ");
else
_screenDisplay.Append($" ");

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

@ -7,7 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp.Menu
namespace ConsoleApp.Menu.Core
{
/// <summary>
/// Define a selection menu.
@ -44,7 +44,7 @@ namespace ConsoleApp.Menu
{
_currentLine = value;
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>
/// <param name="title">The title 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)
{

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

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

@ -5,6 +5,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleApp.Menu.Core;
using Model.Managers;
namespace ConsoleApp.Menu
{
@ -13,12 +15,26 @@ namespace ConsoleApp.Menu
/// </summary>
internal class MainMenu : Menu<IMenu>
{
public MainMenu(DataManager dataMgr)
: base("Main menu",
new Selector<IMenu>(
new SearcherRecipe(new RecipeCollection("search", dataMgr.Data[nameof(Recipe)].Cast<Recipe>().ToArray())), "Recipe search"),
new Selector<IMenu>(
new ConnectionMenu(), "Connection"))
{ }
public MainMenu(MasterManager masterManager)
: base("Main menu")
{
_allSelectors.Add(new Selector<IMenu>(
new SearcherRecipe(masterManager.DataMgr.GetRecipes("search")), "Recipe search"));
_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.Text;
using System.Threading.Tasks;
using ConsoleApp.Menu.Core;
using Model;
namespace ConsoleApp.Menu

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

@ -1,48 +1,26 @@

using ConsoleApp;
using ConsoleApp;
using Model;
using ConsoleApp.Menu;
using DataPersistence;
using System.Linq;
using System.Text;
using Model.Managers;
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:
DataManager dataMgr = new DataManager(new Stubs());
//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");
masterMgr.DataMgr.Serializer = new DataContractXML();
//masterMgr.Serializer = new DataContractJSON();
PasswordManager passwordManager = new PasswordManager();
//RecipeCollection rc = new RecipeCollection("All recipes", dataMgr.Data[nameof(Recipe)].Cast<Recipe>().ToArray());
masterMgr.DataMgr.Save();
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();
Console.WriteLine(passwordManager.VerifyPassword(user.Password, "pamigos"));
Console.ReadKey();

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

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

@ -14,7 +14,6 @@ namespace DataPersistence
{
public Dictionary<string, List<object>> Load()
{
Dictionary<string, List<object>> data = new Dictionary<string, List<object>>
{
{
@ -24,17 +23,22 @@ namespace DataPersistence
{
new Recipe(
title: "Cookies classiques",
id: 50,
authorMail: "admin@mctg.fr",
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[]
{
new PreparationStep(1, "Faire cuire."),
new PreparationStep(2, "Manger.")
}),
new Recipe(
title: "Cookies au chocolat",
picture : "",
id: null,
authorMail: "admin@mctg.fr",
title: "Cookies au chocolat", id: null,
preparationSteps: new[]
{
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 Recipe(
title: "Gateau nature",
picture : "dotnet_bot.svg",
id: null,
title: "Gateau nature", id: null,
authorMail: "admin@mctg.fr",
preparationSteps: new[]
{
new PreparationStep(1, "Achetez les ingrédients."),
@ -52,29 +55,30 @@ namespace DataPersistence
new PreparationStep(3, "Pleurez.")
}),
new Recipe(
title: "Gateau nature",
picture : "dotnet_bot.svg",
id: null,
title: "Gateau au pommes", 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 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 nature",
picture : "dotnet_bot.svg",
id: null,
title: "Gateau au chocolat", id: null,
authorMail: "pedrosamigos@hotmail.com",
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 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",
picture : "",
id: null,
authorMail: "pedrosamigos@hotmail.com",
preparationSteps: new[]
{
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 Recipe(
title: "Gateau nature",
picture : "dotnet_bot.svg",
id: null,
title: "Poulet au curry", id: null,
authorMail: "pedrosamigos@hotmail.com",
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 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),

@ -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.Threading.Tasks;
namespace DataPersistence
namespace Model
{
/// <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.
@ -76,6 +76,30 @@ namespace DataPersistence
public void Export<T>(T obj, string pathToExport)
where T : class
=> 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
}
}

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataPersistence
namespace Model
{
/// <summary>
/// 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>
/// Construct a new step of preparation.
/// </summary>
/// <param name="order">The number of the order in preparation</param>
/// <param name="description">The description of the task</param>
/// <param _name="order">The number of the order in preparation</param>
/// <param _name="description">The description of the task</param>
public PreparationStep(int order, string description = "")
{
Order = order;

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

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

@ -1,4 +1,5 @@
using System;
using Model.Managers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
@ -21,8 +22,8 @@ namespace Model
[DataMember(Name = "id")]
public int Id { get; init; }
[DataMember(Name = "user")]
public User Author { get; private set; }
[DataMember(Name = "authorMail")]
public string AuthorMail { get; private set; }
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)
{
@ -55,24 +56,28 @@ namespace Model
}
else Id = (int)id;
Author = author;
AuthorMail = authorMail;
Stars = stars;
Content = content;
}
public Review(User author, int stars, string content)
: this(author, null, stars, content)
public Review(string authorMail, int stars, string content)
: this(authorMail, null, stars, content)
{
}
public Review(int stars, string content)
: this(new User(), null, stars, content)
: this("admin@mctg.fr", null, stars, content)
{
}
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)

@ -13,7 +13,7 @@ using System.ComponentModel;
namespace Model
{
/// <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
/// </summary>
[DataContract(Name = "user")]
@ -146,7 +146,6 @@ namespace Model
#endregion
#region Constructors
/// <summary>
@ -154,7 +153,9 @@ namespace Model
/// </summary>
/// <param name="name">The name 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 )
{
Name = name;
@ -171,19 +172,28 @@ namespace Model
ProfilPict = picture;
}
/// <summary>
/// <inheritdoc cref="User.User"/>
/// </summary>
public User(string name, string surname, string mail, string password)
: this(name, surname,mail, password, new PasswordManager())
{
}
/// <summary>
/// <inheritdoc cref="User.User"/>
/// </summary>
public User()
: this("John", "Doe", "truc@gmail.com", "mdp")
{
}
/// <summary>
/// <inheritdoc cref="User.User"/>
/// </summary>
public User (User user)
{
Name = user.Name;
@ -197,8 +207,6 @@ namespace Model
#endregion
}
}

@ -1,4 +1,3 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
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" />
</ItemGroup>
</Project>

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

Loading…
Cancel
Save