September 2018
Intermediate to advanced
398 pages
9h 43m
English
The next method to implement is the ability to add a product to the database.
First, we will return a dummy status to avoid IntelliJ errors:
def addProduct() = Action.async { request =>
Future.successful(Ok)
}
Then, we will complete the implementation, as follows:
def addProduct() = Action.async { request =>
val productOrNot = decode[Product] (request.body.asText.getOrElse("")) productOrNot match { case Right(product) => { val futureInsert = productDao.insert(product).recover { case e => { Logger.error("Error while writing in the database", e) InternalServerError("Cannot write in the database") } futureInsert.map(_ ...Read now
Unlock full access