You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
966 B

  1. package controllers
  2. import javax.inject.{Inject, Singleton}
  3. import play.api.mvc._
  4. import play.api.libs.json.Json
  5. import com.example.services.TaskLibraryService
  6. import util.IOHttp._
  7. import com.typesafe.scalalogging.LazyLogging
  8. import cats.effect.IO
  9. import scala.concurrent.ExecutionContext
  10. import util.Schedulers
  11. @Singleton
  12. class MonixHomeController @Inject() (
  13. taskLibraryService: TaskLibraryService,
  14. cc: ControllerComponents
  15. )(schedulers: Schedulers, ec: ExecutionContext)
  16. extends AbstractController(cc)
  17. with LazyLogging {
  18. private implicit val defaultScheduler = schedulers.dbScheduler
  19. def authors(bookId: Long) = Action.asyncF {
  20. for {
  21. _ <- IO(logger.debug("Getting Authors"))
  22. authors <- taskLibraryService.getAuthorsForBook(bookId).to[IO]
  23. _ <- IO(logger.debug("Where am I now?"))
  24. _ <- IO.shift(ec)
  25. _ <- IO(logger.info("Got Authors"))
  26. res <- IO.pure(Ok(Json.toJson(authors)))
  27. } yield (res)
  28. }
  29. }