fix conflicts

pull/55/head
Maxime BATISTA 2 years ago
commit 3b9d9f197a

@ -1,4 +1,7 @@
[*.cs] [*.cs]
# CS0618: Le type ou le membre est obsolète # CS0618: Le type ou le membre est obsolète
dotnet_diagnostic.CS0618.severity = silent dotnet_diagnostic.CS0618.severity = silent
# CS1998: Async method lacks 'await' operators and will run synchronously
dotnet_diagnostic.CS1998.severity = none

@ -24,14 +24,14 @@ namespace ShoopNCook.Controllers
app.ForceLogin(); app.ForceLogin();
} }
public void GoToMyRecipesPage() public async void GoToMyRecipesPage()
{ {
Shell.Current.Navigation.PushAsync(new MyRecipesPage(account, endpoint.RecipesService)); await Shell.Current.Navigation.PushAsync(new MyRecipesPage(account, endpoint.RecipesService));
} }
public void GoToProfilePage() public async void GoToProfilePage()
{ {
Shell.Current.Navigation.PushAsync(new ProfilePage(account)); await Shell.Current.Navigation.PushAsync(new ProfilePage(account));
} }
} }
} }

@ -5,6 +5,8 @@ using System.Collections.Immutable;
using System.Linq; using System.Linq;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace LocalEndpoint.Data namespace LocalEndpoint.Data
@ -62,9 +64,11 @@ namespace LocalEndpoint.Data
Save(ACCOUNTS_FILENAME, ACCOUNTS_SERIALIZER, accountsData); Save(ACCOUNTS_FILENAME, ACCOUNTS_SERIALIZER, accountsData);
} }
public Recipe GetRecipe(Guid id) public Recipe? GetRecipe(Guid id)
{ {
return ConvertRecipeDataToRecipe(recipesData[id]); if (recipesData.TryGetValue(id, out RecipeData? data))
return ConvertRecipeDataToRecipe(data);
return null;
} }
public RecipeRate GetRecipeRate(Guid user, Guid recipe) public RecipeRate GetRecipeRate(Guid user, Guid recipe)
@ -72,38 +76,38 @@ namespace LocalEndpoint.Data
return usersData[user].Rates[recipe]; return usersData[user].Rates[recipe];
} }
public void InsertInUserList(Guid userId, Guid recipeId, uint persAmount) public async void InsertInUserList(Guid userId, Guid recipeId, uint persAmount)
{ {
usersData[userId].RecipesList[recipeId] = persAmount; usersData[userId].RecipesList[recipeId] = persAmount;
Save(USERS_FILENAME, USERS_SERIALIZER, usersData); Save(USERS_FILENAME, USERS_SERIALIZER, usersData);
} }
public void RemoveFromUserList(Guid userId, Guid recipeId) public async void RemoveFromUserList(Guid userId, Guid recipeId)
{ {
usersData[userId].RecipesList.Remove(recipeId); usersData[userId].RecipesList.Remove(recipeId);
Save(USERS_FILENAME, USERS_SERIALIZER, usersData); Save(USERS_FILENAME, USERS_SERIALIZER, usersData);
} }
public void InsertRecipe(Recipe recipe) public async void InsertRecipe(Recipe recipe)
{ {
recipesData[recipe.Info.Id] = new RecipeData(recipe.Info, recipe.Owner.Id, recipe.Ingredients, recipe.Steps); recipesData[recipe.Info.Id] = new RecipeData(recipe.Info, recipe.Owner.Id, recipe.Ingredients, recipe.Steps);
Save(RECIPES_FILENAME, RECIPES_SERIALIZER, recipesData); Save(RECIPES_FILENAME, RECIPES_SERIALIZER, recipesData);
} }
public void InsertUser(User user) public async void InsertUser(User user)
{ {
usersData[user.Id] = new UserData(user, new Dictionary<Guid, RecipeRate>(), new Dictionary<Guid, uint>()); usersData[user.Id] = new UserData(user, new Dictionary<Guid, RecipeRate>(), new Dictionary<Guid, uint>());
Save(USERS_FILENAME, USERS_SERIALIZER, usersData); Save(USERS_FILENAME, USERS_SERIALIZER, usersData);
} }
public void InsertRate(Guid userId, Guid recipeId, RecipeRate rate) public async void InsertRate(Guid userId, Guid recipeId, RecipeRate rate)
{ {
usersData[userId].Rates[recipeId] = rate; usersData[userId].Rates[recipeId] = rate;
Save(USERS_FILENAME, USERS_SERIALIZER, usersData); Save(USERS_FILENAME, USERS_SERIALIZER, usersData);
} }
public void RemoveRecipe(Guid id) public async void RemoveRecipe(Guid id)
{ {
recipesData.Remove(id); recipesData.Remove(id);
Save(RECIPES_FILENAME, RECIPES_SERIALIZER, recipesData); Save(RECIPES_FILENAME, RECIPES_SERIALIZER, recipesData);
@ -141,19 +145,16 @@ namespace LocalEndpoint.Data
if (fileInfo.Length == 0) if (fileInfo.Length == 0)
return new Dictionary<K, V>(); //file is empty thus there is nothing to deserialize return new Dictionary<K, V>(); //file is empty thus there is nothing to deserialize
Console.WriteLine(File.ReadAllText(file));
using (var stream = File.OpenRead(file)) string text = File.ReadAllText(file);
return deserializer.ReadObject(stream) as Dictionary<K, V> ?? throw new Exception("object read from " + file + " is not a dictionnary");
return JsonSerializer.Deserialize<Dictionary<K, V>>(text);
} }
private void Save<K, T>(string fileName, DataContractSerializer serializer, Dictionary<K, T> dict) private async void Save<K, T>(string fileName, DataContractSerializer serializer, Dictionary<K, T> dict)
{ {
using (var stream = File.OpenWrite(dbPath + "/" + fileName)) string json = JsonSerializer.Serialize(dict);
{ File.WriteAllText(dbPath + "/" + fileName, json);
serializer.WriteObject(stream, dict);
stream.Flush();
}
} }
} }

@ -9,7 +9,7 @@ namespace LocalEndpoint.Data
public interface Database public interface Database
{ {
public Recipe GetRecipe(Guid id); public Recipe? GetRecipe(Guid id);
public RecipeRate GetRecipeRate(Guid user, Guid recipe); public RecipeRate GetRecipeRate(Guid user, Guid recipe);

@ -21,7 +21,7 @@ namespace LocalEndpoint
return db.ListAllRecipes().Take(4).ToImmutableList().ConvertAll(v => v.Info); return db.ListAllRecipes().Take(4).ToImmutableList().ConvertAll(v => v.Info);
} }
public Recipe GetRecipe(RecipeInfo info) public Recipe? GetRecipe(RecipeInfo info)
{ {
return db.GetRecipe(info.Id); return db.GetRecipe(info.Id);
} }

@ -8,7 +8,7 @@ namespace Endpoint
{ {
public ImmutableList<RecipeInfo> PopularRecipes(); public ImmutableList<RecipeInfo> PopularRecipes();
public Recipe GetRecipe(RecipeInfo info); public Recipe? GetRecipe(RecipeInfo info);
public IAccountOwnedRecipes GetRecipesOf(Account account); public IAccountOwnedRecipes GetRecipesOf(Account account);
public IAccountRecipesPreferences GetPreferencesOf(Account account); public IAccountRecipesPreferences GetPreferencesOf(Account account);

@ -37,11 +37,9 @@
<!-- Email entry --> <!-- Email entry -->
<Grid <Grid
Grid.Row="1" Grid.Row="1"
RowDefinitions="*, Auto, Auto" RowDefinitions="*, Auto, Auto">
>
<Label <Label
Grid.Row="0" Grid.Row="0"
FontSize="15" FontSize="15"
TextColor="{StaticResource TextColorSecondary}" TextColor="{StaticResource TextColorSecondary}"

@ -16,21 +16,21 @@ public partial class CreateRecipePage : ContentPage
this.onRecipeCreated = onRecipeCreated; this.onRecipeCreated = onRecipeCreated;
} }
private void OnAddIngredientTapped(object sender, TappedEventArgs e) private async void OnAddIngredientTapped(object sender, TappedEventArgs e)
{ {
IngredientList.Children.Add(new IngredientEntry()); IngredientList.Children.Add(new IngredientEntry());
} }
private void OnAddStepTapped(object sender, TappedEventArgs e) private async void OnAddStepTapped(object sender, TappedEventArgs e)
{ {
StepList.Children.Add(new StepEntry((uint) StepList.Children.Count() + 1)); StepList.Children.Add(new StepEntry((uint) StepList.Children.Count() + 1));
} }
private void OnBackButtonClicked(object sender, EventArgs e) private async void OnBackButtonClicked(object sender, EventArgs e)
{ {
Navigation.PopAsync(); Navigation.PopAsync();
} }
private void OnUploadRecipeClicked(object sender, EventArgs e) private async void OnUploadRecipeClicked(object sender, EventArgs e)
{ {
uint callPerPers; uint callPerPers;

@ -27,15 +27,15 @@ public partial class FavoritesPage : ContentPage
RecipeViewLayout.Children.Clear(); RecipeViewLayout.Children.Clear();
preferences.GetFavorites().ForEach(info => preferences.GetFavorites().ForEach(info =>
{ {
RecipeViewLayout.Children.Add(new RecipeView(info, () => RecipeViewLayout.Children.Add(new RecipeView(info, async () =>
{ {
Recipe recipe = service.GetRecipe(info); Recipe? recipe = service.GetRecipe(info);
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1)); await Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1));
})); }));
}); });
} }
private void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e) private async void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e)
{ {
UpdateFavorites(); UpdateFavorites();
} }

@ -1,42 +1,46 @@
namespace ShoopNCook.Pages;
namespace ShoopNCook.Pages; using Models;
using Models; using ShoopNCook.Views;
using ShoopNCook.Views; using Endpoint;
using Endpoint; using LocalEndpoint;
using LocalEndpoint;
public partial class HomePage : ContentPage
public partial class HomePage : ContentPage {
{ public HomePage(Account account, IEndpoint endpoint)
public HomePage(Account account, IEndpoint endpoint) {
{ InitializeComponent();
InitializeComponent();
IRecipesService service = endpoint.RecipesService;
IRecipesService service = endpoint.RecipesService; IAccountRecipesPreferences preferences = service.GetPreferencesOf(account);
IAccountRecipesPreferences preferences = service.GetPreferencesOf(account);
//TODO this code can be factorised
//TODO this code can be factorised void PushRecipe(Layout layout, RecipeInfo info)
void PushRecipe(Layout layout, RecipeInfo info) {
{ layout.Children.Add(new RecipeView(info, () =>
layout.Children.Add(new RecipeView(info, () => {
{ Recipe? recipe = service.GetRecipe(info);
Recipe recipe = service.GetRecipe(info); if (recipe != null)
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1)); Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1));
})); else
} {
UserNotifier.Error("Could not find recipe");
service.PopularRecipes().ForEach(recipe => PushRecipe(PopularsList, recipe)); }
preferences.GetRecommendedRecipes().ForEach(recipe => PushRecipe(RecommendedList, recipe)); }));
}
ProfilePictureImage.Source = ImageSource.FromUri(account.User.ProfilePicture);
ProfilePictureName.Text = account.User.Name; service.PopularRecipes().ForEach(recipe => PushRecipe(PopularsList, recipe));
} preferences.GetRecommendedRecipes().ForEach(recipe => PushRecipe(RecommendedList, recipe));
ProfilePictureImage.Source = ImageSource.FromUri(account.User.ProfilePicture);
ProfilePictureName.Text = account.User.Name;
}
private void OnSyncButtonClicked(object sender, EventArgs e)
{
Shell.Current.Navigation.PushAsync(new SearchPage());
}
private async void OnSyncButtonClicked(object sender, EventArgs e)
{
await Shell.Current.Navigation.PushAsync(new SearchPage());
}
} }

@ -35,7 +35,7 @@ public partial class MyListPage : ContentPage
}); });
} }
private void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e) private async void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e)
{ {
UpdateMyList(); UpdateMyList();
} }

@ -58,11 +58,11 @@ public partial class MyRecipesPage : ContentPage
UserNotifier.Success("Recipe successfully removed"); UserNotifier.Success("Recipe successfully removed");
} }
private void OnBackButtonClicked(object sender, EventArgs e) private async void OnBackButtonClicked(object sender, EventArgs e)
{ {
Navigation.PopAsync(); await Navigation.PopAsync();
} }
private void OnAddRecipeButtonClicked(object sender, EventArgs e) private async void OnAddRecipeButtonClicked(object sender, EventArgs e)
{ {
IAccountOwnedRecipes recipes = service.GetRecipesOf(account); IAccountOwnedRecipes recipes = service.GetRecipesOf(account);

@ -75,7 +75,7 @@ public partial class RecipePage : ContentPage
} }
} }
private void OnFavorite(object o, EventArgs e) private async void OnFavorite(object o, EventArgs e)
{ {
SetFavorite(!isFavorite); SetFavorite(!isFavorite);
if (isFavorite) if (isFavorite)
@ -84,13 +84,13 @@ public partial class RecipePage : ContentPage
preferences.RemoveFromFavorites(info); preferences.RemoveFromFavorites(info);
} }
private void OnSubmitReviewClicked(object o, EventArgs e) private async void OnSubmitReviewClicked(object o, EventArgs e)
{ {
preferences.SetReviewScore(info, note); preferences.SetReviewScore(info, note);
UserNotifier.Success("Your review has been successfuly submited"); UserNotifier.Success("Your review has been successfuly submited");
} }
private void OnAddToMyListClicked(object o, EventArgs e) private async void OnAddToMyListClicked(object o, EventArgs e)
{ {
if (!preferences.AddToWeeklyList(info, Counter.Count)) if (!preferences.AddToWeeklyList(info, Counter.Count))
UserNotifier.Notice("You already added this recipe to you weekly list!"); UserNotifier.Notice("You already added this recipe to you weekly list!");
@ -106,9 +106,9 @@ public partial class RecipePage : ContentPage
else else
Favorite.Source = ImageSource.FromFile("hearth_off.svg"); Favorite.Source = ImageSource.FromFile("hearth_off.svg");
} }
private void OnBackButtonClicked(object sender, EventArgs e) private async void OnBackButtonClicked(object sender, EventArgs e)
{ {
Navigation.PopAsync(); await Navigation.PopAsync();
} }
} }

@ -14,7 +14,7 @@ public partial class RegisterPage : ContentPage
{ {
await Shell.Current.GoToAsync("//Login"); await Shell.Current.GoToAsync("//Login");
} }
private void RegisterTapped(object sender, EventArgs e) private async void RegisterTapped(object sender, EventArgs e)
{ {
string email = EmailEntry.Text; string email = EmailEntry.Text;
string password = PasswordEntry.Text; string password = PasswordEntry.Text;

Binary file not shown.
Loading…
Cancel
Save