40 lines
1.0 KiB
Scala
40 lines
1.0 KiB
Scala
package controllers
|
|
|
|
import javax.inject.{Inject, Singleton}
|
|
|
|
import com.example.user.UserDAO
|
|
import play.api.mvc._
|
|
|
|
import scala.concurrent.ExecutionContext
|
|
import com.example.user.CarDAO
|
|
import com.example.services.LibraryService
|
|
import play.api.libs.json.Json
|
|
|
|
@Singleton
|
|
class HomeController @Inject() (userDAO: UserDAO, carDAO: CarDAO, libraryService: LibraryService, cc: ControllerComponents)
|
|
(implicit ec: ExecutionContext)
|
|
extends AbstractController(cc) {
|
|
|
|
def index = Action.async { implicit request =>
|
|
userDAO.all.map { users =>
|
|
Ok(views.html.index(users))
|
|
}
|
|
}
|
|
|
|
def cars = Action.async { implicit request =>
|
|
carDAO.all.map { cars =>
|
|
Ok(views.html.cars(cars))
|
|
}
|
|
}
|
|
|
|
def book = Action.async{
|
|
// libraryService.findBookById(1).map(e => Ok(Json.toJson(e)))
|
|
// libraryService.insertBookAndAuthor(Book("new book"), Author(2, "Some retard"))
|
|
|
|
for {
|
|
maybeBook <- libraryService.findBookById(1)
|
|
} yield (Ok(Json.toJson(maybeBook)))
|
|
}
|
|
|
|
}
|