Closed MRlolface249 closed 1 year ago
Hello Alex. Good effort! I can see you trying to implement profile picture field using mongoDB. and here is my thought. I will let you know what I understand so far and give you some suggestion.
First, when the user add a movie in their favourite list, the movie ID will be added in the Profile Picture (pfp).
Then, user pfp will display the FIRST movie that uses add in their favourite list ( = first in pfp database), which you demonstrate here, you want to get the first item ([0] index) in the pfp database.
Let's start with database structure. I found out that the favourite and the profilePicture field are most likely identical. (see in userModal)
I think the pfp in the userModal field here can be consider as duplicated in this point. it does not have unique property here, therefore it might not be necessary to have its own field. We can just use the favourite field (in mongoDB) to get the movie image (using movieId).
Instead of creating a new profile field in the database, it will be more efficient just to use favourites, as the pfp is really depends on the movie in the favourite list. By doing so, this line of code might not be necessary, which reduce the complexity of the code.
Furthermore, we also need to think about if the user does not have movie in the favourite list yet, There is two approach can solve this issue.
First, we simply use the default pfp, which I am using now. OR Second, you can create a unique pfp (like Luca suggested last time - the github pfp or random movie) when the user signing up. In this case pfp field in MongoDB can be used to store the url for the generated pfp.
These issues have been accounted for, the "duplicate code" still remains but this is because they are unique and have different implementations, it is however true that they could possibly both use a shared helper function to avoid duplicate code
This pull request contributes to #80 and adds functionality which when an account is created a default profile picture is added to the users account, after which any time you add a movie to your favourites list, your profile picture will be replaced with this movie if it is the only movie in your list. Whenever you remove a movie from the list if the list becomes empty your profile picture goes back to the default image, if not it checks that the set profile picture is still in the list, and if it is not it changes, the profile picture to another movie in your favourites list.