Skip to content

Commit 8fcae82

Browse files
committed
More changes
1 parent f54a1c0 commit 8fcae82

File tree

10 files changed

+427
-193
lines changed

10 files changed

+427
-193
lines changed

10.0/Apps/WhatToEat/src/WhatToEat/Constants.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

10.0/Apps/WhatToEat/src/WhatToEat/MockRestService.cs

Lines changed: 208 additions & 17 deletions
Large diffs are not rendered by default.
Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,26 @@
1-
using System.Text.Json.Serialization;
2-
3-
namespace Recipes
1+
namespace Recipes
42
{
53
public class RecipeData
64
{
7-
[JsonPropertyName("q")]
8-
public string QueryText { get; set; }
9-
10-
[JsonPropertyName("from")]
11-
public int StartIndex { get; set; }
12-
13-
[JsonPropertyName("to")]
14-
public int EndIndex { get; set; }
15-
16-
[JsonPropertyName("hits")]
175
public Hit[] Hits { get; set; }
186
}
197

208
public class Hit
219
{
22-
[JsonPropertyName("recipe")]
2310
public Recipe Recipe { get; set; }
24-
2511
public int Id { get; set; }
2612
}
2713

2814
public class Recipe
2915
{
30-
[JsonPropertyName("label")]
3116
public string RecipeName { get; set; }
3217

33-
[JsonPropertyName("ingredientLines")]
3418
public string[] Ingredients { get; set; }
3519

36-
[JsonPropertyName("image")]
20+
public string[] Tags { get; set; }
21+
3722
public string ImageUrl { get; set; }
3823

39-
[JsonPropertyName("url")]
4024
public string RecipeUrl { get; set; }
4125
}
42-
}
26+
}

10.0/Apps/WhatToEat/src/WhatToEat/ViewModels/SearchResultsViewModel.cs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async Task OnSearch()
8484

8585
if (!string.IsNullOrWhiteSpace(SearchQuery) || !string.IsNullOrWhiteSpace(SearchFilter))
8686
{
87-
RecipeData recipeData = await _restService.GetRecipeDataAsync(GenerateRequestUri(Constants.EdamamEndpoint));
87+
RecipeData recipeData = await _restService.GetRecipeDataAsync(SearchFilter);
8888

8989
if (recipeData == null || recipeData.Hits.Length == 0)
9090
{
@@ -108,30 +108,6 @@ async Task OnSearch()
108108
}
109109
}
110110

111-
string GenerateRequestUri(string endpoint)
112-
{
113-
string searchFilterName = SearchFilter.Substring(SearchFilter.IndexOf("=") + 1);
114-
115-
if (string.IsNullOrEmpty(SearchQuery))
116-
{
117-
SearchQuery = searchFilterName;
118-
}
119-
120-
string requestUri = endpoint;
121-
requestUri += $"?q={SearchQuery}";
122-
requestUri += $"&app_id={Constants.EdamamAppId}";
123-
requestUri += $"&app_key={Constants.EdamamAppKey}";
124-
requestUri += $"&to=100";
125-
126-
if (!string.IsNullOrEmpty(SearchFilter))
127-
{
128-
Title = $"Search {searchFilterName} recipes";
129-
requestUri += $"&{SearchFilter}";
130-
}
131-
132-
return requestUri;
133-
}
134-
135111
async void OnItemSelected(Hit hit)
136112
{
137113
if (hit == null)

10.0/Apps/WhatToEat/src/WhatToEat/ViewModels/StartingPageViewModel.cs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,37 +34,13 @@ async Task OnSearch(string filter = null)
3434
// Require query and/or filter to search
3535
if (!string.IsNullOrWhiteSpace(SearchQuery) || !string.IsNullOrWhiteSpace(filter))
3636
{
37-
RecipeData recipeData = await _restService.GetRecipeDataAsync(GenerateRequestUri(Constants.EdamamEndpoint, filter));
37+
RecipeData recipeData = await _restService.GetRecipeDataAsync(filter);
3838

3939
string urlEncodedFilter = System.Net.WebUtility.UrlEncode(filter);
4040
await Shell.Current.GoToAsync($"{nameof(SearchResultsPage)}?SearchQuery={SearchQuery}&SearchFilter={urlEncodedFilter}");
4141

4242
SearchQuery = string.Empty;
4343
}
4444
}
45-
46-
string GenerateRequestUri(string endpoint, string filter)
47-
{
48-
string requestUri = endpoint;
49-
50-
if (string.IsNullOrEmpty(SearchQuery) && !string.IsNullOrEmpty(filter))
51-
{
52-
requestUri += $"?q={filter.Substring(filter.IndexOf("=") + 1)}";
53-
}
54-
else
55-
{
56-
requestUri += $"?q={SearchQuery}";
57-
}
58-
59-
requestUri += $"&app_id={Constants.EdamamAppId}";
60-
requestUri += $"&app_key={Constants.EdamamAppKey}";
61-
62-
if (!string.IsNullOrEmpty(filter))
63-
{
64-
requestUri += $"&{filter}";
65-
}
66-
67-
return requestUri;
68-
}
6945
}
7046
}

9.0/Apps/WhatToEat/src/WhatToEat/Constants.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)