fixes
continuous-integration/drone/push Build is passing Details

master
Maxime BATISTA 2 years ago
parent b2678b485e
commit 73dbd82dfb

@ -1,5 +1,6 @@
using Models;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Text;
using System.Text.Json;
@ -52,6 +53,7 @@ namespace LocalServices.Data
{
accountsData[account.Email] = new AccountData(account.User.Id, account.Email, passwordHash);
Save(ACCOUNTS_FILENAME, accountsData);
InsertUser(account.User);
}
public Recipe? GetRecipe(Guid id)
@ -170,6 +172,7 @@ namespace LocalServices.Data
}
catch (IOException e)
{
Debug.WriteLine(e + " in thread " + Thread.CurrentThread);
if (fs != null)
fs.Dispose();

@ -17,7 +17,7 @@ namespace LocalServices.Data
public Recipe? GetRecipe(Guid id)
{
return new Recipe(new RecipeInfo("Foo", 4, 5, new Uri("https://th.bing.com/th/id/R.e57009c4044bef3e86f8a7b18a7cf36a?rik=K3dSu3KoTgeRSw&pid=ImgRaw&r=0"), 4.5F, id), User, new List<Ingredient> { new Ingredient("Chocolate", 4) }.ToImmutableList(), new List<PreparationStep> { new PreparationStep("Eat Chocolate", "Eat the chocolate") }.ToImmutableList());
return new Recipe(new RecipeInfo("Foo", 4, 5, new Uri("https://th.bing.com/th/id/R.e57009c4044bef3e86f8a7b18a7cf36a?rik=K3dSu3KoTgeRSw&pid=ImgRaw&r=0"), 4.5F, id), User, new List<Ingredient> { new Ingredient("Chocolate", 4, "g") }.ToImmutableList(), new List<PreparationStep> { new PreparationStep("Eat Chocolate", "Eat the chocolate") }.ToImmutableList());
}
public ImmutableDictionary<Guid, uint> GetRecipeListOf(Guid user)

@ -51,12 +51,12 @@ namespace LocalServices
db.InsertAccount(new Account(USER2, "yanis@google.com"), "123456");
db.InsertAccount(new Account(USER3, "leo@google.com"), "123456");
db.InsertRecipe(new Recipe(new RecipeInfo("Chicken Salad", 500, 20, new Uri("https://healthyfitnessmeals.com/wp-content/uploads/2021/04/Southwest-chicken-salad-7-500x500.jpg"), 4, Guid.NewGuid()), USER1, new List<Ingredient> { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List<PreparationStep> { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList()));
db.InsertRecipe(new Recipe(new RecipeInfo("Chocolate Cake", 2500, 10, new Uri("https://bakewithshivesh.com/wp-content/uploads/2022/08/IMG_0248-scaled.jpg"), 3, Guid.NewGuid()), USER2, new List<Ingredient> { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List<PreparationStep> { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList()));
db.InsertRecipe(new Recipe(new RecipeInfo("Salmon", 20, 10, new Uri("https://www.wholesomeyum.com/wp-content/uploads/2021/06/wholesomeyum-Pan-Seared-Salmon-Recipe-13.jpg"), 4, Guid.NewGuid()), USER1, new List<Ingredient> { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List<PreparationStep> { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList()));
db.InsertRecipe(new Recipe(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, Guid.NewGuid()), USER3, new List<Ingredient> { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List<PreparationStep> { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList()));
db.InsertRecipe(new Recipe(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, Guid.NewGuid()), USER3, new List<Ingredient> { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List<PreparationStep> { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList()));
db.InsertRecipe(new Recipe(new RecipeInfo("Cupcake", 500, 12, new Uri("https://www.mycake.fr/wp-content/uploads/2015/12/rs_cupcake_4x3.jpg"), 4.2F, Guid.NewGuid()), USER1, new List<Ingredient> { new Ingredient("Chocolate", 4) }.ToImmutableList(), new List<PreparationStep> { new PreparationStep("Eat Chocolate", "Eat the chocolate") }.ToImmutableList()));
db.InsertRecipe(new Recipe(new RecipeInfo("Chicken Salad", 500, 20, new Uri("https://healthyfitnessmeals.com/wp-content/uploads/2021/04/Southwest-chicken-salad-7-500x500.jpg"), 4, Guid.NewGuid()), USER1, new List<Ingredient> { new Ingredient("Ingredient 1", 6, "g") }.ToImmutableList(), new List<PreparationStep> { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList()));
db.InsertRecipe(new Recipe(new RecipeInfo("Chocolate Cake", 2500, 10, new Uri("https://bakewithshivesh.com/wp-content/uploads/2022/08/IMG_0248-scaled.jpg"), 3, Guid.NewGuid()), USER2, new List<Ingredient> { new Ingredient("Ingredient 1", 6, "g") }.ToImmutableList(), new List<PreparationStep> { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList()));
db.InsertRecipe(new Recipe(new RecipeInfo("Salmon", 20, 10, new Uri("https://www.wholesomeyum.com/wp-content/uploads/2021/06/wholesomeyum-Pan-Seared-Salmon-Recipe-13.jpg"), 4, Guid.NewGuid()), USER1, new List<Ingredient> { new Ingredient("Ingredient 1", 6, "g") }.ToImmutableList(), new List<PreparationStep> { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList()));
db.InsertRecipe(new Recipe(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, Guid.NewGuid()), USER3, new List<Ingredient> { new Ingredient("Ingredient 1", 6, "g") }.ToImmutableList(), new List<PreparationStep> { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList()));
db.InsertRecipe(new Recipe(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, Guid.NewGuid()), USER3, new List<Ingredient> { new Ingredient("Ingredient 1", 6, "g") }.ToImmutableList(), new List<PreparationStep> { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList()));
db.InsertRecipe(new Recipe(new RecipeInfo("Cupcake", 500, 12, new Uri("https://www.mycake.fr/wp-content/uploads/2015/12/rs_cupcake_4x3.jpg"), 4.2F, Guid.NewGuid()), USER1, new List<Ingredient> { new Ingredient("Chocolate", 4, "g") }.ToImmutableList(), new List<PreparationStep> { new PreparationStep("Eat Chocolate", "Eat the chocolate") }.ToImmutableList()));
}
/// <summary>

@ -9,5 +9,5 @@ namespace Models
/// <param name="Name">The ingredient's name</param>
/// <param name="Amount">The ingredient's amount (in kilograms or liters)</param>
[DataContract]
public record Ingredient([property: DataMember] string Name, [property: DataMember] float Amount);
public record Ingredient([property: DataMember] string Name, [property: DataMember] float Amount, [property: DataMember] string Unit);
}

@ -149,9 +149,6 @@
<MauiXaml Update="ConnectAppShell.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\Components\NoticePopup.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\CreateRecipePage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>

@ -1,15 +1,9 @@
using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Maui.Core;
using CommunityToolkit.Maui.Views;
using ShoopNCook.Views.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShoopNCook
{
namespace ShoopNCook
{
internal class UserNotifier
{
private static async Task Show(string message, string messageType)
@ -23,8 +17,8 @@ namespace ShoopNCook
var toast = Toast.Make(message, duration, fontSize);
await toast.Show(cancellationTokenSource.Token);
}
}
public static void Error(string message)
@ -43,6 +37,6 @@ namespace ShoopNCook
{
Show(message, "Success");
}
}
}
}
}

@ -22,7 +22,7 @@
Style="{StaticResource UserInput}"
Placeholder="Ingredient Name"
HeightRequest="40"
x:Name="NameEntry"/>
Text="{Binding NameText, Mode=OneWayToSource}"/>
</Border>
<Border
Grid.Column="1"
@ -35,7 +35,7 @@
Placeholder="Quantity"
HeightRequest="40"
Keyboard="Numeric"
x:Name="QuantityEntry"/>
Text="{Binding QuantityText, Mode=OneWayToSource}"/>
</Border>
<Border
Grid.Column="2"

@ -5,23 +5,28 @@ namespace ShoopNCook.Views;
// Classe représentant une entrée d'ingrédient
public partial class IngredientEntry : ContentView
{
public string QuantityText { get; set; }
public string NameText { get; set; }
public IngredientEntry()
{
BindingContext = this;
InitializeComponent();
}
// Renvoie une nouvelle instance de Ingredient à partir des informations entrées par l'utilisateur
public Ingredient MakeValue()
public Ingredient? MakeValue()
{
float quantity;
// Tente de convertir la quantité en float, sinon, attribue une valeur par défaut de 0
if (!float.TryParse(QuantityEntry.Text, out quantity))
if (!float.TryParse(QuantityText, out quantity) || quantity < 0)
{
quantity = 0;
// TODO handle quantity text malformation by raising exception
UserNotifier.Error("La quantité doit être un nombre positif");
return null;
}
return new Ingredient(NameEntry.Text, quantity);
return new Ingredient(NameText, quantity, UnitPicker.SelectedItem as string);
}
}

@ -41,6 +41,6 @@ public partial class IngredientView : ContentView
Name = ingredient.Name;
Quantity = ingredient.Amount;
//TODO Unit implementation in IngredientView.xaml.cs
Unit = "TODO: Unit implementation in IngredientView.xaml.cs";
Unit = ingredient.Unit;
}
}

@ -1,10 +0,0 @@
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ShoopNCook.Views.Components.NoticePopup">
<VerticalStackLayout>
<Label
x:Name="MessageLabel"
VerticalOptions="Center"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ContentView>

@ -1,39 +0,0 @@
namespace ShoopNCook.Views.Components;
using Microsoft.Maui.Graphics;
public partial class NoticePopup : ContentView
{
public NoticePopup(string message, string messageType)
{
InitializeComponent();
MessageLabel.Text = message;
switch (messageType)
{
case "Error":
this.BackgroundColor = Microsoft.Maui.Graphics.Colors.Red;
break;
case "Warning":
this.BackgroundColor = Microsoft.Maui.Graphics.Colors.Yellow;
break;
case "Notice":
this.BackgroundColor = Microsoft.Maui.Graphics.Colors.Blue;
break;
case "Success":
this.BackgroundColor = Microsoft.Maui.Graphics.Colors.Green;
break;
}
// Display the toast for 3 seconds
Device.StartTimer(TimeSpan.FromSeconds(3), () =>
{
// Close the toast
// You need to replace this with your actual code to close the toast
this.IsVisible = false;
return false;
});
}
}

@ -61,8 +61,12 @@ public partial class CreateRecipePage : ContentPage
//TODO .SetImage(RecipeImage)
;
foreach (IngredientEntry entry in IngredientList.Children)
builder.AddIngredient(entry.MakeValue());
foreach (IngredientEntry entry in IngredientList.Children)
{
var ingredient = entry.MakeValue();
if (ingredient == null) return;
builder.AddIngredient(ingredient);
}
foreach (StepEntry entry in StepList.Children)
builder.AddStep(entry.MakeStep());

Loading…
Cancel
Save