diff --git a/backend-services/feed-service/app/controllers/DailyController.scala b/backend-services/feed-service/app/controllers/DailyController.scala new file mode 100644 index 0000000000000000000000000000000000000000..5cd5d85cdab37da9f4ac3a99321e4dfa0fef8131 --- /dev/null +++ b/backend-services/feed-service/app/controllers/DailyController.scala @@ -0,0 +1,39 @@ +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") + } + } +} diff --git a/backend-services/feed-service/conf/routes b/backend-services/feed-service/conf/routes index c987e3139a94547944c6f45cb7398242a2986f69..bb8d194f7f31d00212f5c3390ceb86f840ce1eed 100644 --- a/backend-services/feed-service/conf/routes +++ b/backend-services/feed-service/conf/routes @@ -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()