O'Reilly logo

Building Applications with Scala by Diego Pacheco

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Refactoring controllers

Now we have all the dao packages implemented with the respective database evolutions. However, our services expected a different contract, since we were using an in-memory database before. Let's refactor the product controller:

 package controllers @Singleton class ProductController @Inject() (val messagesApi:MessagesApi,val service:IProductService) extends Controller with I18nSupport { val productForm: Form[Product] = Form( mapping( "id" -> optional(longNumber), "name" -> nonEmptyText, "details" -> text, "price" -> bigDecimal )(models.Product.apply)(models.Product.unapply) ) def index = Action { implicit request => val products = Awaits.get(5,service.findAll()) .getOrElse(Seq()) Logger.info("index called. Products: " + ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required