Add feed page that displays recipes pertaining to users' followed tags. - #89
Add feed page that displays recipes pertaining to users' followed tags.#89nonsensicle wants to merge 7 commits into
Conversation
…s. Currently, these recipes cannot be sorted using a SortingMethod.
| List<String> followedTagIds = followedTagIds(userId); | ||
| // Query for recipes matching the followed tag Ids. | ||
| return recipesMatchingAnyTags(followedTagIds); | ||
| } |
There was a problem hiding this comment.
If you want to do sorting, you could add some code like this (does sort on our end without firestore's help):
switch (sortingMethod) {
case TOP:
System.out.println("Sorting by: TOP");
Collections.sort(
results, Collections.reverseOrder(Comparator.comparingLong(RecipeMetadata::getVotes)));
break;
case NEW:
System.out.println("Sorting by: NEW");
Collections.sort(results,
Collections.reverseOrder(Comparator.comparingLong(RecipeMetadata::getTimestamp)));
break;
}
There was a problem hiding this comment.
Here, getVotes and getTimestamp are simple getters I added on my branch
| boolean isTagQuery = (tagIDs != null && tagIDs.length > 0 && !tagIDs[0].equals("None")); | ||
| boolean isCreatorQuery = (creatorToken != null && !creatorToken.equals("None")); | ||
| boolean isFollowedTagsQuery = (isCreatorQuery && sortingMethod == SortingMethod.TAGS); | ||
|
|
There was a problem hiding this comment.
What if the user wants to sort by new or top for their custom feed? I feel like we should have some other flag to determine whether it's a followedTagsQuery
| break; | ||
| } | ||
| metadata.addAll( | ||
| getRecipeMetadataQuery(recipes.whereEqualTo("tagIds." + tagId, true), SortingMethod.TOP)); |
There was a problem hiding this comment.
This is probably not the way we want to go about doing this... considering that there's no limit on the number of recipes in each tag, eventually, the feed will consist of literally just the one tag.
Also: it might be better to have a timestamp limit rather than a hard recipe limit, so maybe change to using that?
For example, the limit might be recipes from last week for now, and later, we can think about changing that as a potential feature.
There was a problem hiding this comment.
@bradleypickard @hari387 im not sure how hard it would be, but we could try a top of last week, top of last month, top of all time sort of thing... for now i'll hard code as Last Week since getting a lot more recipes than that is going to be significantly more complicated
| try { | ||
| return followedTagsRecipes.subList( | ||
| (page * RECIPES_PER_PAGE), ((page + 1) * RECIPES_PER_PAGE)); | ||
| } catch (IndexOutOfBoundsException e) { |
There was a problem hiding this comment.
wouldn't you get this exception when you try to get the last page?
…ecipeServlet; get recipes from last week in FirestoreDB getRecipesMatchingAnyTags()
| for (String tagId : tagIds) { | ||
| // Get only relevant recipes from the last week. | ||
| Calendar calendar = Calendar.getInstance(); | ||
| calendar.add(Calendar.WEEK_OF_YEAR, -1); |
There was a problem hiding this comment.
Does this work when it is currently the first week of the year?
There was a problem hiding this comment.
That's a good question -- I'll have to look into it, but I think it should
Currently, these recipes cannot be sorted using a SortingMethod because a Firestore OR query cannot be constructed programmatically and thus cannot be sorted as normal queries.