Skip to content

Commit

Permalink
adding hash to posts in timeline and posts request
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Mar 24, 2017
1 parent 864ac0e commit 4e97fa3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/maxdemarzi/posts/Posts.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public Response getPosts(@PathParam("username") final String username,

try (Transaction tx = db.beginTx()) {
Node user = Users.findUser(username, db);
Map userProperties = user.getAllProperties();
int count = 0;
while (count < limit && (dateTime.isAfter(earliest))) {
RelationshipType relType = RelationshipType.withName("POSTED_ON_" +
Expand All @@ -56,6 +57,9 @@ public Response getPosts(@PathParam("username") final String username,
for (Relationship r1 : user.getRelationships(Direction.OUTGOING, relType)) {
Map<String, Object> post = r1.getEndNode().getAllProperties();
if((Long)post.get("time") < latest) {
post.put(USERNAME, username);
post.put(NAME, userProperties.get(NAME));
post.put(HASH, userProperties.get(HASH));
results.add(post);
count++;
}
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/maxdemarzi/timeline/Timeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ public Response getTimeline(@PathParam("username") final String username,
dateTime.format(dateFormatter));

for (Node follow : follows) {
String followUsername = (String)follow.getProperty(USERNAME);
String followName = (String)follow.getProperty(NAME);
Map followProperties = follow.getAllProperties();

for (Relationship r1 : follow.getRelationships(Direction.OUTGOING, posted)) {
Node post = r1.getEndNode();
if(seen.add(post.getId())) {
Map<String, Object> properties = r1.getEndNode().getAllProperties();
if ((Long) properties.get("time") < latest) {
properties.put(USERNAME, followUsername);
properties.put(NAME, followName);
properties.put(USERNAME, followProperties.get(USERNAME));
properties.put(NAME, followProperties.get(NAME));
properties.put(HASH, followProperties.get(HASH));
properties.put(LIKES, post.getDegree(RelationshipTypes.LIKES));
properties.put(REPOSTS, post.getDegree() - 1 - post.getDegree(RelationshipTypes.LIKES));
results.add(properties);
Expand All @@ -84,8 +84,9 @@ public Response getTimeline(@PathParam("username") final String username,
Map<String, Object> properties = r1.getEndNode().getAllProperties();
Long time = (Long)properties.get("time");
if (time < latest) {
properties.put(REPOSTERUSERNAME, followUsername);
properties.put(REPOSTERNAME, followName);
properties.put(REPOSTERUSERNAME, followProperties.get(USERNAME));
properties.put(REPOSTERNAME, followProperties.get(NAME));
properties.put(HASH, followProperties.get(HASH));
properties.put(LIKES, post.getDegree(RelationshipTypes.LIKES));
properties.put(REPOSTS, post.getDegree() - 1 - post.getDegree(RelationshipTypes.LIKES));

Expand Down
7 changes: 7 additions & 0 deletions src/test/java/com/maxdemarzi/posts/GetPostsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void shouldGetPostsSince() {
private static final String FIXTURE =
"CREATE (max:User {username:'maxdemarzi', " +
"email: 'max@neo4j.com', " +
"hash: 'hash', " +
"name: 'Max De Marzi'," +
"password: 'swordfish'})" +
"CREATE (post1:Post {status:'Hello World!', " +
Expand All @@ -60,10 +61,16 @@ public void shouldGetPostsSince() {
add(new HashMap<String, Object>() {{
put("status", "How are you!");
put("time", 1490208700);
put("name", "Max De Marzi");
put("username", "maxdemarzi");
put("hash", "hash");
}});
add(new HashMap<String, Object>() {{
put("status", "Hello World!");
put("time", 1490140299);
put("name", "Max De Marzi");
put("username", "maxdemarzi");
put("hash", "hash");
}});
}};
}
7 changes: 7 additions & 0 deletions src/test/java/com/maxdemarzi/timeline/GetTimelineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,17 @@ public void shouldGetTimelineSince() {
private static final String FIXTURE =
"CREATE (max:User {username:'maxdemarzi', " +
"email: 'max@neo4j.com', " +
"hash: 'hash', " +
"name: 'Max De Marzi'," +
"password: 'swordfish'})" +
"CREATE (jexp:User {username:'jexp', " +
"email: 'michael@neo4j.com', " +
"hash: 'hash', " +
"name: 'Michael Hunger'," +
"password: 'tunafish'})" +
"CREATE (laeg:User {username:'laexample', " +
"email: 'luke@neo4j.com', " +
"hash: 'hash', " +
"name: 'Luke Gannon'," +
"password: 'cuddlefish'})" +

Expand All @@ -77,6 +80,7 @@ public void shouldGetTimelineSince() {
add(new HashMap<String, Object>() {{
put("username", "maxdemarzi");
put("name", "Max De Marzi");
put("hash", "hash");
put("status", "Doing fine!");
put("time", 1490208800);
put("likes", 0);
Expand All @@ -85,6 +89,7 @@ public void shouldGetTimelineSince() {
add(new HashMap<String, Object>() {{
put("username", "laexample");
put("name", "Luke Gannon");
put("hash", "hash");
put("status", "How are you!");
put("time", 1490208700);
put("likes", 0);
Expand All @@ -93,6 +98,7 @@ public void shouldGetTimelineSince() {
add(new HashMap<String, Object>() {{
put("reposter_username", "laexample");
put("reposter_name", "Luke Gannon");
put("hash", "hash");
put("username", "jexp");
put("name", "Michael Hunger");
put("status", "Hello World!");
Expand All @@ -105,6 +111,7 @@ public void shouldGetTimelineSince() {
private static final HashMap<String, Object> unReposted = new HashMap<String, Object>() {{
put("username", "jexp");
put("name", "Michael Hunger");
put("hash", "hash");
put("status", "Hello World!");
put("time", 1490140299);
put("likes", 1);
Expand Down

0 comments on commit 4e97fa3

Please sign in to comment.