add MyList registraction to LocalEndpoint and app side
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

pull/50/head
maxime.BATISTA@etu.uca.fr 2 years ago
parent 4638b3efd6
commit 8ca9eaea7f

@ -1,10 +1,5 @@
using Models; using Models;
using System;
using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Endpoint namespace Endpoint
{ {
@ -16,6 +11,7 @@ namespace Endpoint
public void AddToFavorites(RecipeInfo info); public void AddToFavorites(RecipeInfo info);
public void RemoveFromFavorites(RecipeInfo info); public void RemoveFromFavorites(RecipeInfo info);
public void SetReviewScore(RecipeInfo info, uint score); public void SetReviewScore(RecipeInfo info, uint score);
public bool AddToWeeklyList(RecipeInfo info, uint persAmount);
public AccountRecipeRate GetRate(RecipeInfo info); public AccountRecipeRate GetRate(RecipeInfo info);

@ -76,6 +76,17 @@ namespace LocalEndpoint
ratings[info.Id] = new AccountRecipeRate(true, rate.Rate); ratings[info.Id] = new AccountRecipeRate(true, rate.Rate);
} }
public bool AddToWeeklyList(RecipeInfo info, uint persAmount)
{
if (weekly.ContainsKey(info.Id))
return false;
weekly[info.Id] = persAmount;
return true;
}
public void RemoveFromFavorites(RecipeInfo info) public void RemoveFromFavorites(RecipeInfo info)
{ {
AccountRecipeRate rate = GetRate(info); AccountRecipeRate rate = GetRate(info);

@ -4,7 +4,8 @@
x:Class="ShoopNCook.Pages.MyListPage" x:Class="ShoopNCook.Pages.MyListPage"
Title="MyList" Title="MyList"
BackgroundColor="{StaticResource BackgroundPrimary}" BackgroundColor="{StaticResource BackgroundPrimary}"
xmlns:views="clr-namespace:ShoopNCook.Views"> xmlns:views="clr-namespace:ShoopNCook.Views"
NavigatedTo="ContentPage_NavigatedTo">
<Grid <Grid
RowDefinitions="Auto, *, Auto"> RowDefinitions="Auto, *, Auto">
<!-- Header label and return button --> <!-- Header label and return button -->

@ -7,11 +7,25 @@ namespace ShoopNCook.Pages;
public partial class MyListPage : ContentPage public partial class MyListPage : ContentPage
{ {
private readonly IAccountRecipesPreferences preferences;
private readonly IUserNotifier notifier;
private readonly IRecipesService service;
public MyListPage(Account account, IUserNotifier notifier, IRecipesService service) public MyListPage(Account account, IUserNotifier notifier, IRecipesService service)
{ {
InitializeComponent(); InitializeComponent();
IAccountRecipesPreferences preferences = service.GetPreferencesOf(account); this.preferences = service.GetPreferencesOf(account);
this.notifier = notifier;
this.service = service;
UpdateMyList();
}
private void UpdateMyList()
{
RecipesLayout.Children.Clear();
preferences.GetWeeklyList().ForEach(tuple => preferences.GetWeeklyList().ForEach(tuple =>
{ {
RecipeInfo info = tuple.Item1; RecipeInfo info = tuple.Item1;
@ -21,6 +35,10 @@ public partial class MyListPage : ContentPage
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, amount)); Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, amount));
})); }));
}); });
}
private void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e)
{
UpdateMyList();
} }
} }

@ -171,7 +171,8 @@
Text="Add to list" Text="Add to list"
Style="{StaticResource UserButton}" Style="{StaticResource UserButton}"
TextColor="White" TextColor="White"
BackgroundColor="Gray"> BackgroundColor="Gray"
Clicked="OnAddToMyListClicked">
</Button> </Button>
</FlexLayout> </FlexLayout>
</Grid> </Grid>

@ -88,6 +88,14 @@ public partial class RecipePage : ContentPage
notifier.Success("Your review has been successfuly submited"); notifier.Success("Your review has been successfuly submited");
} }
private void OnAddToMyListClicked(object o, EventArgs e)
{
if (!preferences.AddToWeeklyList(info, Counter.Count))
notifier.Notice("You already added this recipe to you weekly list!");
else
notifier.Success("Recipe added to your weekly list.");
}
private void SetFavorite(bool isFavorite) private void SetFavorite(bool isFavorite)
{ {
this.isFavorite = isFavorite; this.isFavorite = isFavorite;

Loading…
Cancel
Save