Skip to content
Snippets Groups Projects
Commit 5dd1c420 authored by Felipe D'Abrantes's avatar Felipe D'Abrantes
Browse files

Add query parameters to test endpoints

parent 04ca8aed
No related branches found
No related tags found
1 merge request!14Add endpoints to manage Dailies
......@@ -12,8 +12,10 @@ import play.api.libs.json.JsBoolean
@Singleton
class TestController @Inject()(val controllerComponents: ControllerComponents) extends BaseController {
def getFriends() = Action {
def getFriends(userId: String) = Action {
println("TestController:getFriends")
println(s"Fetching friends for User with ID {$userId}")
val response = JsArray(
Seq(
JsString("641128f7e80bcd1ba39d04ae"),
......@@ -25,7 +27,10 @@ class TestController @Inject()(val controllerComponents: ControllerComponents) e
Ok(response)
}
def verifyUser() = Action {
def verifyUser(userId: String) = Action {
println("TestController:verifyUser")
println(s"Verifying User with ID {$userId}")
Ok(JsBoolean(true))
}
}
......@@ -18,7 +18,7 @@ object HttpCall {
*
* @return a Future containing the response body as a JSON.
*/
def get(url: String): Future[JsValue] = {
def get(url: String, queryStringParameters: (String, String)*): Future[JsValue] = {
// Create ActorSystem for thread and streaming management
implicit val system: ActorSystem = ActorSystem()
......@@ -29,7 +29,9 @@ object HttpCall {
val wsClient: StandaloneAhcWSClient = StandaloneAhcWSClient()
// Call API and fetch response
val response: Future[JsValue] = wsClient.url(url).get().map { response =>
val response: Future[JsValue] = wsClient.url(url).addQueryStringParameters(queryStringParameters: _*).get().map { response =>
if (response.status > 399) throw new RuntimeException()
val statusText: String = response.statusText
println(s"Got a response: $statusText")
response.body[JsValue]
......
......@@ -12,7 +12,7 @@ object User {
def getUserFriends(userId: ObjectId): Future[Seq[ObjectId]] = {
println(s"Fetching friends for user with ID {$userId}")
HttpCall.get("http://localhost:9000/test/getFriends").map[Seq[ObjectId]]((json: JsValue) => {
HttpCall.get("http://localhost:9000/test/getFriends", ("userId", userId.toString())).map[Seq[ObjectId]]((json: JsValue) => {
val sequence: Seq[String] = json.as[Seq[String]]
sequence.map[ObjectId](new ObjectId(_))
})
......@@ -21,6 +21,6 @@ object User {
def userExists(userId: ObjectId): Future[Boolean] = {
println(s"Verifying user with ID {$userId} exists")
HttpCall.get("http://localhost:9000/test/verifyUser").map[Boolean](_.as[Boolean])
HttpCall.get("http://localhost:9000/test/verifyUser", ("userId", userId.toString())).map[Boolean](_.as[Boolean])
}
}
......@@ -58,7 +58,7 @@ class AuthenticationTransformer @Inject() (implicit val executionContext: Execut
}
catch {
case ex: Throwable => {
println(ex)
println(s"JWT Error: $ex")
None
}
}
......
......@@ -22,6 +22,6 @@ PUT /daily/like controllers.DailyController.like()
PUT /daily/unlike controllers.DailyController.unlike()
GET /test/getFriends controllers.TestController.getFriends()
GET /test/getFriends controllers.TestController.getFriends(userId: String)
GET /test/verifyUser controllers.TestController.verifyUser()
GET /test/verifyUser controllers.TestController.verifyUser(userId: String)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment