2020-05-16 10:10:23 +00:00
|
|
|
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
|
2020-05-17 18:00:24 +00:00
|
|
|
class HomeController @Inject() (
|
|
|
|
userDAO: UserDAO,
|
|
|
|
carDAO: CarDAO,
|
|
|
|
libraryService: LibraryService,
|
|
|
|
cc: ControllerComponents
|
|
|
|
)(implicit ec: ExecutionContext)
|
|
|
|
extends AbstractController(cc) {
|
2020-05-16 10:10:23 +00:00
|
|
|
|
|
|
|
def index = Action.async { implicit request =>
|
2020-05-17 18:00:24 +00:00
|
|
|
userDAO.all.map { users => Ok(views.html.index(users)) }
|
2020-05-16 10:10:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def cars = Action.async { implicit request =>
|
2020-05-17 18:00:24 +00:00
|
|
|
carDAO.all.map { cars => Ok(views.html.cars(cars)) }
|
2020-05-16 10:10:23 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 18:00:24 +00:00
|
|
|
def book = Action.async {
|
2020-05-16 10:10:23 +00:00
|
|
|
// 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)))
|
|
|
|
}
|
|
|
|
|
2020-05-17 18:00:24 +00:00
|
|
|
def authors(bookId: Long) = Action.async { implicit request =>
|
|
|
|
libraryService.getAuthorsForBook(bookId).map( t => {
|
|
|
|
Ok(Json.toJson(t))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-16 10:10:23 +00:00
|
|
|
}
|