Database Reference
In-Depth Information
Listing 12-28. The follow Method in UserAction and follow Service Method in UserDAO
@Action(value = "follow/{username}",results = {@Result(name = "success", type = "json")})
public String follow() {
try {
graphStory.setFollowing(graphStoryDAO.getUserDAO()
.follow(
cookiesMap.get(GraphStoryConstants.graphstoryUserAuthKey),
graphStory.getUsername()
));
}
catch (Exception e) {
log.error(e);
}
return SUCCESS;
}
// follow and return new list of following
public List<User> follow(String currentusername, String username) {
try
{
ResultSet resultSet = cypher.resultSetQuery(
" MATCH (user1:User {username:{1}} ),(user2:User {username:{2}} )" +
" CREATE UNIQUE user1-[:FOLLOWS]->user2" +
" WITH user1" +
" MATCH (user1)-[f:FOLLOWS]->(users)" +
" RETURN users " +
" ORDER BY users.username",
map("1", currentusername, "2", username));
ResultSetMapper<User> resultSetMapper = new ResultSetMapper<User>();
return resultSetMapper.mapRersultSetToObject(resultSet, User.class);
}
catch (Exception e) {
log.error(e);
return null;
}
}
The unfollow feature uses an application flow nearly identical to the follows feature. In the unfollow method,
shown in Listing 12-29, the controller passes in two arguments: the current username and username to be
unfollowed. Once completed, the unfollow route returns the updated collection of users being followed.
 
Search WWH ::




Custom Search