Browsing Genres

Optional Lesson

This lesson is optional and will not count towards your achievement. To view the completed code, check out the 09-genre-list branch.

If you click on the Genres link in the main navigation, you will be taken to a list of Genres. This list is populated by the API route at http://localhost:3000/api/genres, with the list being produced by the all() method within the GenreService.

js
src/services/genre.service.js
Unresolved directive in lesson.adoc - include::https://raw.githubusercontent.com/neo4j-graphacademy/llm-chatbot-python/main/src/services/genre.service.js[tag=all]

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

cypher
Listing Genres
Unresolved directive in lesson.adoc - include::{cypher-repository-raw}/main/cypher/3-backlog/1-browse-genres/genre-details.cypher[]

Your Task

  • Modify the all() method on the GenreService to query Neo4j and return a list of properties ordered by genre name.

  • Each genre should have a name, the number of movies listed in that genre (movies), and a poster image (from the most popular movie in that genre).

  • Remember to close the session and use the toNativeTypes() function within a map() function on res.records to convert the values to native JavaScript types.

Open src/services/genre.service.js

Working Solution

Click here to view the completed all() method.
js
src/services/genre/genre.service.js
Unresolved directive in lesson.adoc - include::https://raw.githubusercontent.com/neo4j-graphacademy/llm-chatbot-python/09-genre-list/src/services/genre.service.js[tag=all]

Testing

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

sh
Running the test
npm run test 09

The test file is located at test/challenges/09-genre-list.spec.js.

Are you stuck? Click here for help

If you get stuck, you can see a working solution by checking out the 09-genre-list branch by running:

sh
Check out the 09-genre-list branch
git checkout 09-genre-list

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

Which genre has the highest movie count?

After the test has succeeded, the test suite will log the name of the genre with the greatest number of movies.

Enter the name of the genre below and click Check Answer.

  • ✓ Drama

Hint

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

cypher
Unresolved directive in questions/1-movie-count.adoc - include::{cypher-repository-raw}/main/cypher/3-backlog/1-browse-genres/genre-with-most-movies.cypher[]

Copy the answer without any quotes or whitespace.

Lesson Summary

In this Challenge, you updated the GenreService to retrieve a list of genres from the database.

In the next Challenge, you will update the GenreService to query Neo4j to find the details of an individual genre.

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?