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

Implement endpoint for fetching all Dailies (#19)

parent 92ffb5c2
No related branches found
No related tags found
1 merge request!14Add endpoints to manage Dailies
package controllers
import javax.inject._
import play.api._
import play.api.mvc._
import models.Daily
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.{Future, Await, TimeoutException}
import scala.concurrent.duration._
import org.bson.types.ObjectId
/**
* This controller handles all the Daily endpoints.
*/
@Singleton
class DailyController @Inject()(val controllerComponents: ControllerComponents) extends BaseController {
/**
* Create an Action to fetch all the Dailies in the DB.
*/
def getAll() = Action { implicit request: Request[AnyContent] =>
println("DailyController:getAll")
var result = Daily.getAllDailies()
try {
// Wait for 4 seconds for the Future to complete
val resultCompleted = Await.result(result, 4.seconds)
val jsonResult: Seq[String] = resultCompleted.map(daily => Daily.toString(daily))
Ok(jsonResult.toString())
} catch {
case e: TimeoutException =>
BadRequest("Request timed out")
}
}
}
......@@ -10,3 +10,5 @@ GET / controllers.HomeController.index()
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
GET /mongo_test controllers.MongoTestController.index()
GET /daily/getAll controllers.DailyController.getAll()
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