Desktop version

Home arrow Computer Science arrow Building Applications with Scala

Source

Adding the report to the review controller

Now is the time to create the report function for the review controller. Here we go.

Your ReviewController.scala file, after adding a report function, should look something like this:

@Singleton

class ReviewController @Inject()

(val messagesApi:MessagesApi,

val productService:IProductService, val service:IReviewService) extends Controller with I18nSupport {

//... rest of the controller code... def report() = Action {

import play.api.libs.concurrent.Execution.

Implicits.defaultContext Ok.chunked( Enumerator.fromStream( ReportBuilder.toPdf("Reviews.jrxml") ) )

.withHeaders(CONTENT_TYPE -> "application/octet-stream") .withHeaders(CONTENT_DISPOSITION -> "attachment; filename=report-reviews.pdf")

}

}

We have the same logic here as we have for the product controller. The main difference is the jrxml file and the filename response header. Now, we can move to the last controller-the image controller.

Adding the report to the image controller

Finally, we will apply the same logic here as we did for the product and review controller, but now it is time to change the image controller. Your imageController.scala file, after adding report function, should look something like this:

@Singleton

class ImageController @Inject()

(val messagesApi:MessagesApi,

val productService:IProductService, val service:IImageService) extends Controller with I18nSupport {

// ... rest of the controller code ... def report() = Action {

import play.api.libs.concurrent.Execution. Implicits.defaultContext Ok.chunked( Enumerator.fromStream( ReportBuilder.toPdf("Images.jrxml") ) )

.withHeaders(CONTENT_TYPE -> "application/octet-stream") .withHeaders(CONTENT_DISPOSITION -> "attachment; filename=report-images.pdf")

}

}

Alright, we have finished all the controllers. However, we will need to configure routes, otherwise, we won't be able to call the controllers-this is the next step.

 
Source
Found a mistake? Please highlight the word and press Shift + Enter  
< Prev   CONTENTS   Next >

Related topics