35 lines
966 B
Scala
35 lines
966 B
Scala
|
package controllers
|
||
|
|
||
|
import javax.inject.{Inject, Singleton}
|
||
|
import play.api.mvc._
|
||
|
import play.api.libs.json.Json
|
||
|
import com.example.services.TaskLibraryService
|
||
|
import util.IOHttp._
|
||
|
import com.typesafe.scalalogging.LazyLogging
|
||
|
import cats.effect.IO
|
||
|
import scala.concurrent.ExecutionContext
|
||
|
import util.Schedulers
|
||
|
|
||
|
@Singleton
|
||
|
class MonixHomeController @Inject() (
|
||
|
taskLibraryService: TaskLibraryService,
|
||
|
cc: ControllerComponents
|
||
|
)(schedulers: Schedulers, ec: ExecutionContext)
|
||
|
extends AbstractController(cc)
|
||
|
with LazyLogging {
|
||
|
|
||
|
private implicit val defaultScheduler = schedulers.dbScheduler
|
||
|
|
||
|
def authors(bookId: Long) = Action.asyncF {
|
||
|
for {
|
||
|
_ <- IO(logger.debug("Getting Authors"))
|
||
|
authors <- taskLibraryService.getAuthorsForBook(bookId).to[IO]
|
||
|
_ <- IO(logger.debug("Where am I now?"))
|
||
|
_ <- IO.shift(ec)
|
||
|
_ <- IO(logger.info("Got Authors"))
|
||
|
res <- IO.pure(Ok(Json.toJson(authors)))
|
||
|
} yield (res)
|
||
|
}
|
||
|
|
||
|
}
|