Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This repository accompanies the link:https://graphacademy.neo4j.com/courses/app-java/[Building Neo4j Applications with Java course^] on link:https://graphacademy.neo4j.com/[Neo4j GraphAcademy^].

For a complete walkthrough of this repository, link:https://graphacademy.neo4j.com/courses/app-java/[enroll now^].
For a complete walkthrough of this repository, link:https://graphacademy.neo4j.com/courses/app-java/[enroll now^].

== Setup

Expand All @@ -16,22 +16,27 @@ sdk install java 17-open
sdk use java 17-open
sdk install maven
mvn verify
mvn compile exec:java
----

.Connection details to your neo4j database are in `src/main/resources/application.properties`
[source,properties]
----
APP_PORT=3000

NEO4J_URI=bolt://hostname-or-ip:7687
NEO4J_URI=bolt://<hostname-or-ip>:7687
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=<password>

JWT_SECRET=secret
SALT_ROUNDS=10
----

.Run the application
[source,shell]
----
mvn compile exec:java
----

== A Note on comments

You may spot a number of comments in this repository that look a little like this:
Expand Down
39 changes: 23 additions & 16 deletions src/main/java/neoflix/services/PeopleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,20 @@ public Map<String, Object> findById(String id) {

// Get a person from the database
var person = session.executeRead(tx -> {
String query = """
MATCH (p:Person {tmdbId: $id})
RETURN p {
.*,
actedCount: count { (p)-[:ACTED_IN]->() },
directedCount: count { (p)-[:DIRECTED]->() }
} AS person
""";
var res = tx.run(query, Values.parameters("id", id));
return res.single().get("person").asMap();
});
String query = """
MATCH (p:Person {tmdbId: $id})
WITH p,
count { (p)-[:ACTED_IN]->() } AS actedCount,
count { (p)-[:DIRECTED]->() } AS directedCount
RETURN p {
.*,
actedCount: actedCount,
directedCount: directedCount
} AS person
""";
var res = tx.run(query, Values.parameters("id", id));
return res.single().get("person").asMap();
});
return person;
}
}
Expand All @@ -108,13 +111,17 @@ public List<Map<String,Object>> getSimilarPeople(String id, Params params) {
// Get a list of similar people to the person by their id
var res = session.executeRead(tx -> tx.run("""
MATCH (:Person {tmdbId: $id})-[:ACTED_IN|DIRECTED]->(m)<-[r:ACTED_IN|DIRECTED]-(p)
WITH p,
count { (p)-[:ACTED_IN]->() } AS actedCount,
count { (p)-[:DIRECTED]->() } AS directedCount,
collect(m {.tmdbId, .title, type: type(r)}) AS inCommon
RETURN p {
.*,
actedCount: count { (p)-[:ACTED_IN]->() },
directedCount: count { (p)-[:DIRECTED]->() },
inCommon: collect(m {.tmdbId, .title, type: type(r)})
.*,
actedCount: actedCount,
directedCount: directedCount,
inCommon: inCommon
} AS person
ORDER BY size(person.inCommon) DESC
ORDER BY size(inCommon) DESC
SKIP $skip
LIMIT $limit
""",Values.parameters("id",id, "skip", params.skip(), "limit", params.limit()))
Expand Down