September 2018
Intermediate to advanced
398 pages
9h 43m
English
The first method that we are going to implement is the list of products. As you will remember from Chapter 6, Online Shopping – Persistence, we created a list of default products upon the creation of the application. Hence, our first task will be to get these products and send them back as JSON objects.
As we have already written a data access layer, the extraction from the database is pretty simple. Indeed, we just need to call the all() method from the product DAO instance, as follows:
def listProduct() = Action.async { request =>
val futureProducts = productDao.all()
for (
products <- futureProducts
) yield (Ok(products.mkstring(",")))
}
The productDao.all() method returns all of the products from the database as Future[Seq[Product]] ...
Read now
Unlock full access