convert current Models to records, unencapsulate RecipeState into Recipe and AccountRecipeRate
continuous-integration/drone/push Build is passing Details

pull/50/head
maxime.BATISTA@etu.uca.fr 2 years ago
parent adda823bf9
commit 60d3d6267c

@ -15,6 +15,6 @@ namespace Endpoint
public Recipe GetRecipe(RecipeInfo info); public Recipe GetRecipe(RecipeInfo info);
public RecipeState RecipeStateOf(Account account, Recipe recipe); public AccountRecipeRate GetRateOf(Account account, Recipe recipe);
} }
} }

@ -9,11 +9,11 @@ namespace LocalEndpoint
public List<RecipeInfo> PopularRecipes() public List<RecipeInfo> PopularRecipes()
{ {
return new List<RecipeInfo> { return new List<RecipeInfo> {
new RecipeInfo("Chicken Curry", 45, new Uri("https://cdn.chefclub.tools/uploads/recipes/cover-thumbnail/f287b191-dc8e-4c85-bbb6-e26387c354d3.jpg"), 3), new RecipeInfo("Chicken Curry", 500, 45, new Uri("https://cdn.chefclub.tools/uploads/recipes/cover-thumbnail/f287b191-dc8e-4c85-bbb6-e26387c354d3.jpg"), 3),
new RecipeInfo("Spaghetti Bolognese", 30, new Uri("https://media.istockphoto.com/id/1144823591/fr/photo/spaghetti-dans-un-plat-sur-un-fond-blanc.jpg?s=612x612&w=0&k=20&c=qFzd8iE185mpsX7hWqYaieOWlzJVCkzFdYsxmwUT3-Q="), 1), new RecipeInfo("Spaghetti Bolognese", 1000, 30, new Uri("https://media.istockphoto.com/id/1144823591/fr/photo/spaghetti-dans-un-plat-sur-un-fond-blanc.jpg?s=612x612&w=0&k=20&c=qFzd8iE185mpsX7hWqYaieOWlzJVCkzFdYsxmwUT3-Q="), 1),
new RecipeInfo("Beef Stroganoff", 10, new Uri("https://www.cookwithnabeela.com/wp-content/uploads/2023/02/BeefStroganoff.webp"), 5), new RecipeInfo("Beef Stroganoff", 100, 10, new Uri("https://www.cookwithnabeela.com/wp-content/uploads/2023/02/BeefStroganoff.webp"), 5),
new RecipeInfo("Fish And Ships", 15, new Uri("https://upload.wikimedia.org/wikipedia/commons/f/ff/Fish_and_chips_blackpool.jpg"), 4), new RecipeInfo("Fish And Ships", 450, 15, new Uri("https://upload.wikimedia.org/wikipedia/commons/f/ff/Fish_and_chips_blackpool.jpg"), 4),
new RecipeInfo("Caesar Salad", 20, new Uri("https://www.galbani.fr/wp-content/uploads/2020/04/AdobeStock_157570276-2.jpeg"), 1) new RecipeInfo("Caesar Salad", 150, 20, new Uri("https://www.galbani.fr/wp-content/uploads/2020/04/AdobeStock_157570276-2.jpeg"), 1)
}; };
} }
@ -21,11 +21,11 @@ namespace LocalEndpoint
public List<RecipeInfo> RecommendedRecipes(Account account) public List<RecipeInfo> RecommendedRecipes(Account account)
{ {
return new List<RecipeInfo> { return new List<RecipeInfo> {
new RecipeInfo("Chicken Salad", 20, new Uri("https://healthyfitnessmeals.com/wp-content/uploads/2021/04/Southwest-chicken-salad-7-500x500.jpg"), 4), new RecipeInfo("Chicken Salad", 500, 20, new Uri("https://healthyfitnessmeals.com/wp-content/uploads/2021/04/Southwest-chicken-salad-7-500x500.jpg"), 4),
new RecipeInfo("Chocolate Cake", 10, new Uri("https://bakewithshivesh.com/wp-content/uploads/2022/08/IMG_0248-scaled.jpg"), 3), new RecipeInfo("Chocolate Cake", 2500, 10, new Uri("https://bakewithshivesh.com/wp-content/uploads/2022/08/IMG_0248-scaled.jpg"), 3),
new RecipeInfo("Salmon", 10, new Uri("https://www.wholesomeyum.com/wp-content/uploads/2021/06/wholesomeyum-Pan-Seared-Salmon-Recipe-13.jpg"), 4), new RecipeInfo("Salmon", 20, 10, new Uri("https://www.wholesomeyum.com/wp-content/uploads/2021/06/wholesomeyum-Pan-Seared-Salmon-Recipe-13.jpg"), 4),
new RecipeInfo("Fish", 30, new Uri("https://www.ciaanet.org/wp-content/uploads/2022/07/Atlantic-and-Pacific-whole-salmon-1024x683.jpg"), 4.5F), new RecipeInfo("Fish", 50, 30, new Uri("https://www.ciaanet.org/wp-content/uploads/2022/07/Atlantic-and-Pacific-whole-salmon-1024x683.jpg"), 4.5F),
new RecipeInfo("Space Cake", 5, new Uri("https://static.youmiam.com/images/recipe/1500x1000/space-cake-22706?placeholder=web_recipe&sig=f14a7a86da837c6b8cc678cde424d6d5902f99ec&v3"), 5) new RecipeInfo("Space Cake", 800, 5, new Uri("https://static.youmiam.com/images/recipe/1500x1000/space-cake-22706?placeholder=web_recipe&sig=f14a7a86da837c6b8cc678cde424d6d5902f99ec&v3"), 5)
}; };
} }
@ -37,10 +37,10 @@ namespace LocalEndpoint
return new Recipe(info, owner, ingredients, steps); return new Recipe(info, owner, ingredients, steps);
} }
public RecipeState RecipeStateOf(Account account, Recipe recipe) public AccountRecipeRate GetRateOf(Account account, Recipe recipe)
{ {
Random random = new Random(); Random random = new Random();
return new RecipeState((uint) random.Next(1, 10), random.Next() % 2 == 0, (uint)random.Next(0, 6), recipe); return new AccountRecipeRate(random.Next() % 2 == 0, (uint)random.Next(0, 6));
} }

@ -1,15 +1,4 @@
namespace Models namespace Models
{ {
public class Account public record Account(User User, string Email);
{
public Account(User usr, string mail)
{
User = usr;
Email = mail;
}
public User User { get; init; }
public string Email { get; init; }
}
} }

@ -0,0 +1,5 @@

namespace Models
{
public record AccountRecipeRate(bool IsFavorite, uint Rate);
}

@ -1,15 +1,4 @@
namespace Models namespace Models
{ {
public class Ingredient public record Ingredient(string Name, float Amount);
{
public Ingredient(string name, float amount)
{
Name = name;
Amount = amount;
}
public string Name { get; init; }
public float Amount { get; init; }
}
} }

@ -1,15 +1,5 @@
namespace Models namespace Models
{ {
public class PreparationStep public record PreparationStep(string Name, string Description);
{
public PreparationStep(string name, string description)
{
Name = name;
Description = description;
}
public string Name { get; init; }
public string Description { get; init; }
}
} }

@ -1,25 +1,8 @@
namespace Models namespace Models
{ {
public class Recipe public record Recipe(
{ RecipeInfo Info,
User Owner,
public RecipeInfo Info { get; init; } List<Ingredient> Ingredients,
List<PreparationStep> Steps);
public User Owner { get; init; }
public List<Ingredient> Ingredients { get; init; }
public List<PreparationStep> Steps { get; init; }
public Recipe(
RecipeInfo info,
User owner,
List<Ingredient> ingredients,
List<PreparationStep> steps)
{
Info = info;
Owner = owner;
Ingredients = ingredients;
Steps = steps;
}
}
} }

@ -1,21 +1,4 @@
namespace Models namespace Models
{ {
public class RecipeInfo public record RecipeInfo(string Name, uint CalPerPers, uint CookTimeMins, Uri Image, float AverageNote);
{
public string Name { get; init; }
public uint CookTimeMins { get; init; }
public uint Energy { get; init; }
public Uri Image { get; init; }
public float AverageNote { get; init; }
public RecipeInfo(string name, uint cookTimeMins, Uri image, float averageNote)
{
Name = name;
CookTimeMins = cookTimeMins;
Image = image;
AverageNote = averageNote;
}
}
} }

@ -1,22 +0,0 @@

namespace Models
{
public class RecipeState
{
public uint PersonAmount { get; private init; }
public bool IsAccountFavorite { get; private init; }
public uint AccountNote { get; private init; }
public Recipe Recipe { get; private init; }
public RecipeState(uint personAmount, bool isAccountFavorite, uint accountNote, Recipe recipe)
{
PersonAmount = personAmount;
IsAccountFavorite = isAccountFavorite;
AccountNote = accountNote;
Recipe = recipe;
}
}
}

@ -1,15 +1,4 @@
namespace Models namespace Models
{ {
public class User public record User(Uri ProfilePicture, string Name);
{
public User(Uri profilePicture, string name)
{
ProfilePicture = profilePicture;
Name = name;
}
public Uri ProfilePicture { get; init; }
public string Name { get; init; }
}
} }

@ -17,8 +17,8 @@ public partial class HomePage : ContentPage
layout.Children.Add(new RecipeView(info, () => layout.Children.Add(new RecipeView(info, () =>
{ {
Recipe recipe = service.GetRecipe(info); Recipe recipe = service.GetRecipe(info);
RecipeState state = service.RecipeStateOf(account, recipe); AccountRecipeRate rate = service.GetRateOf(account, recipe);
Shell.Current.Navigation.PushAsync(new RecipePage(state)); Shell.Current.Navigation.PushAsync(new RecipePage(recipe, rate, 1));
})); }));
} }

@ -12,22 +12,22 @@ public partial class RecipePage : ContentPage
public ICommand StarCommand => new Command<string>(count => SetNote(uint.Parse(count))); public ICommand StarCommand => new Command<string>(count => SetNote(uint.Parse(count)));
public RecipePage(RecipeState state) public RecipePage(Recipe recipe, AccountRecipeRate rate, uint amount)
{ {
InitializeComponent(); InitializeComponent();
Recipe recipe = state.Recipe; Counter.Count = amount;
RecipeInfo info = recipe.Info;
note = state.AccountNote; note = rate.Rate;
isFavorite = state.IsAccountFavorite; isFavorite = rate.IsFavorite;
Counter.Count = state.PersonAmount;
SetFavorite(isFavorite); SetFavorite(isFavorite);
SetNote(note); SetNote(note);
RecipeInfo info = recipe.Info;
CookTime.Text = info.CookTimeMins.ToString(); CookTime.Text = info.CookTimeMins.ToString();
Energy.Text = info.Energy.ToString(); Energy.Text = info.CalPerPers.ToString() + " cal/pers";
RecipeName.Text = info.Name; RecipeName.Text = info.Name;
foreach (Ingredient ingredient in recipe.Ingredients) foreach (Ingredient ingredient in recipe.Ingredients)

Loading…
Cancel
Save