Listing Ratings

Optional Lesson

This lesson is optional and will not count towards your achievement. To view the completed code, check out the 13-listing-ratings branch.

The last remaining element on the Movie page is the list of ratings on the right-hand side of the page. Although the count in the header is now accurate, the ratings list being returned by the API is still hardcoded.

The list of ratings is populated by the for_movie() method in the RatingDAO, which currently returns a hardcoded list of ratings.

python
api/dao/ratings.py
Unresolved directive in lesson.adoc - include::{repository-raw}/main/api/dao/ratings.py[tag=forMovie]

In this challenge, you will run the following Cypher statement in a read transaction:

cypher
Get Ratings
Unresolved directive in lesson.adoc - include::{cypher-repository-raw}/main/cypher/3-backlog/5-listing-ratings/listing-ratings.cypher[]

Your Task

  • Modify the for_movie() method to retrieve the ratings from Neo4j.

  • Remember to use the .format() method on the string to replace the r.timestamp value from the query above with the sort parameter supplied to the method and escape the braces in the Cypher statement using double braces ({{ and }}).

Click to reveal the completed for_movie() method
python
api/dao/ratings.py
Unresolved directive in lesson.adoc - include::{repository-raw}/13-listing-ratings/api/dao/ratings.py[tag=forMovie]

Testing

To test that this functionality has been correctly implemented, run the following code in a new terminal session:

sh
Running the test
pytest -s tests/13_listing_ratings__test.py

The test file is located at tests/13_listing_ratings__test.py.

Are you stuck? Click here for help

If you get stuck, you can see a working solution by checking out the 13-listing-ratings branch by running:

sh
Check out the 13-listing-ratings branch
git checkout 13-listing-ratings

You may have to commit or stash your changes before checking out this branch. You can also click here to expand the Support pane.

Verifying the Test

Who was the first user to rate Pulp Fiction?

As part of the test suite, the final test will log the name of the first user to rate the movie Pulp Fiction.

Paste the name of the user the box below without quotes or whitespace and click Check Answer.

  • ✓ Keith Howell

Hint

You can also find the answer by running the following Cypher statement:

cypher
Unresolved directive in questions/1-first-rating.adoc - include::{cypher-repository-raw}/main/cypher/3-backlog/5-listing-ratings/first-rating.cypher[]

Copy the answer without any quotes or whitespace.

Lesson Summary

In this Challenge, you modified the for_movie() method on the RatingDAO to return a paginated list of reviews for a movie from the Neo4j database.

In the next Challenge, you will update the PersonDAO to return list of actors and directors from Neo4j.

Chatbot

Hi, I am an Educational Learning Assistant for Intelligent Network Exploration. You can call me E.L.A.I.N.E.

How can I help you today?