Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
import java.time.Instant
import com.gvolpe.social.model.{Country, Person, PersonIdentifier}
import com.gvolpe.social.service.DefaultSocialNetworkService
object Playground extends App {
val client = DefaultSocialNetworkService
val p1 = Person(1, "Gabi", 29, "Argentina", "Software Engineer")
val p2 = Person(2, "Damian", 29, "Argentina", "Software Engineer")
val p3 = Person(3, "John", 30, "Ireland", "Pilot")
val p4 = Person(4, "Mike", 32, "England", "Architect")
val p5 = Person(5, "Chris", 22, "Germany", "Marketing")
val p6 = Person(6, "Guille", 24, "Argentina", "Sales")
val p7 = Person(7, "Ivan", 21, "Argentina", "Student")
val p8 = Person(8, "Gustavo", 35, "Argentina", "Lawyer")
val p9 = Person(9, "Capusotto", 57, "Argentina", "President")
def follow(from: Person, to: Person, timestamp: Instant) = {
client.createFollower(from, to, timestamp).unsafePerformSync
}
client.createPerson(p1)
client.createPerson(p2)
client.createPerson(p3)
client.createPerson(p4)
client.createPerson(p5)
client.createPerson(p6)
client.createPerson(p7)
client.createPerson(p8)
client.createPerson(p9)
follow(p1, p2, Instant.parse("2015-07-01T00:00:00.00Z")) // Gabi --> Damian
follow(p1, p3, Instant.parse("2015-11-25T00:00:00.00Z")) // Gabi --> John
follow(p1, p6, Instant.parse("2007-01-23T00:00:00.00Z")) // Gabi --> Guille
follow(p2, p1, Instant.parse("2015-08-14T00:00:00.00Z")) // Damian --> Gabi
follow(p2, p3, Instant.parse("2014-10-20T00:00:00.00Z")) // Damian --> John
follow(p2, p8, Instant.parse("2009-05-18T00:00:00.00Z")) // Damian --> Gustavo
follow(p3, p5, Instant.parse("2010-05-17T00:00:00.00Z")) // John --> Chris
follow(p4, p1, Instant.parse("2012-03-07T00:00:00.00Z")) // Mike --> Gabi
follow(p4, p6, Instant.parse("2010-07-01T00:00:00.00Z")) // Mike --> Guille
follow(p6, p1, Instant.parse("2017-02-27T00:00:00.00Z")) // Guille --> Gabi
follow(p7, p1, Instant.parse("2017-03-01T00:00:00.00Z")) // Ivan --> Gabi
follow(p8, p9, Instant.parse("2008-06-13T00:00:00.00Z")) // Gustavo --> Capusotto
follow(p9, p8, Instant.parse("2016-08-02T00:00:00.00Z")) // Capusotto --> Gustavo
println(s"${p1.name}'s followers: ")
println(client.findFollowers(PersonIdentifier(p1.id)))
println("")
println(s"${p1.name} is following: ")
println(client.findFollowing(PersonIdentifier(p1.id)))
println("")
println(s"${p1.name}'s followers with ages between 20 and 25: ")
println(client.findFollowersWithAgeRange(PersonIdentifier(p1.id), 20, 25))
println("")
println(s"${p1.name}'s followers from Argentina and count: ")
println(client.findFollowersFrom(PersonIdentifier(p1.id), Country("Argentina")))
println("")
println(s"${p1.name}'s followers count from Argentina: ")
println(client.followersFromCount(PersonIdentifier(p1.id), Country("Argentina")))
println("")
println(s"Can I reach ${p1.name}'s president by common connections? ")
println(client.findPresidentByCommonConnections(PersonIdentifier(p1.id), Country("Argentina")))
println("")
println(s"Path to ${p1.name}'s president? ")
val path = client.findPathToPresident(PersonIdentifier(p1.id), Country("Argentina"))
println(path.map(_.name).mkString(" --> "))
println("")
println(s"${p1.name}'s followers since January 2017: ")
println(client.findFollowersSince(PersonIdentifier(p1.id), Instant.parse("2017-01-01T00:00:00.00Z")))
println("")
println(s"What's the first follower of whom ${p4.name} has first started following? ")
client.findFirstFollowerOfTopOne(PersonIdentifier(p4.id)).foreach { kv =>
println(s">>> ${p4.name} has first started following ${kv._1}")
println(s">>> and ${kv._1.name}'s first follower is ${kv._2}")
}
println("")
println(s"What's the first follower of whom ${p5.name} has first started following? ")
client.findFirstFollowerOfTopOne(PersonIdentifier(p5.id)).foreach { kv =>
println(s">>> ${p5.name} has first started following ${kv._1}")
println(s">>> and ${kv._1.name}'s first follower is ${kv._2}")
}
client.g.close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment