Update: git repo: https://github.com/muhsinali/picture-example-minifiedThis is my first project that I've written using Scala and the Play framework. It's a simple application that allows the user to store pictures and see them (no edit/delete functionality, just to keep the code review simple).I have included a couple of questions as TODOs in the source code (only 1 Scala file).Please comment on how I could improve the readability and structure of the code.routes file:GET     /                                   controllers.Application.indexPOST    /                                   controllers.Application.upload()GET     /get-picture-of-place/:name         controllers.Application.getPictureOfPlace(name: String)Application.scala (contains the model and controller):package controllersimport javax.inject.Injectimport com.google.common.io.Filesimport play.api.data.Formimport play.api.data.Forms._import play.api.mvc.{Action, Controller}import play.modules.reactivemongo.{MongoController, ReactiveMongoApi, ReactiveMongoComponents}import reactivemongo.api.ReadPreferenceimport reactivemongo.api.collections.bson.BSONCollectionimport reactivemongo.bson.{BSONDocument, Macros}//TODO how do I used DI instead of these two imports?import play.api.Play.currentimport play.api.i18n.Messages.Implicits._import scala.concurrent.{ExecutionContext, Future}case class PlaceData(name: String)case class Place(name: String, picture: Array[Byte])object Place {  implicit val formatter = Macros.handler[Place]}class Application @Inject()(val reactiveMongoApi: ReactiveMongoApi)(implicit ec: ExecutionContext) extends Controller  with MongoController with ReactiveMongoComponents {  def index = Action.async {implicit request =>    retrieveAllPlaces.map(places => Ok(views.html.main(places, Application.createPlaceForm)))  }  def placesFuture: Future[BSONCollection] = database.map(_.collection[BSONCollection](places))  def retrieveAllPlaces: Future[List[Place]] = {    val placesList = placesFuture.flatMap({      _.find(BSONDocument()).        cursor[Place](ReadPreference.Primary).        collect[List]()    })    placesList  }  // TODO would like to use an ID that's generated internally (find out how to use ObjectID from MongodDB database)  def findByName(name: String): Future[Option[Place]] = {    val foundPlace = placesFuture.flatMap({      _.find(BSONDocument(name -> name)).one[Place](ReadPreference.Primary)    })    foundPlace  }  def getPictureOfPlace(name: String) = Action.async{    findByName(name).map(placeOpt =>      if (placeOpt.isDefined) Ok(placeOpt.get.picture)      else BadRequest(sCould not retrieve the place named $name)    )  }  def upload = Action.async(parse.multipartFormData) { implicit request =>    val boundForm = Application.createPlaceForm.bindFromRequest()    boundForm.fold(     formWithErrors => {       // TODO pass in formWithErrors into index method so that the form is populated with the values.       Future(Redirect(routes.Application.index()).flashing(error -> Could not upload place. Please correct the form below.))     },      placeData => {        placesFuture.flatMap(places => {          request.body.file(picture).map { picture =>            places.insert(Place(placeData.name, Files.toByteArray(picture.ref.file)))            Future(Redirect(routes.Application.index()).flashing(success -> Successfully added place))          }.getOrElse {            Future(Redirect(routes.Application.index()).flashing(error -> Could not upload place. Please correct the form below.))          }        })    })  }}object Application {  val createPlaceForm = Form(    mapping(      name -> nonEmptyText    )(PlaceData.apply)(PlaceData.unapply)  )}main.scala.html (the view):    @(placesList: List[Place], form: Form[PlaceData])(implicit flash: Flash, messages: Messages)<html><head>    <link rel=stylesheet media=screen href=https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css>    <title>Places</title></head><body class=container>@if(flash.get(success).isDefined){    <div class=alert alert-success>        @flash.get(success)    </div>}@if(flash.get(error).isDefined){    <div class=alert alert-danger>        @flash.get(error)    </div>}@helper.form(action = routes.Application.upload, 'enctype -> multipart/form-data) {    <fieldset>    <legend>Add new place:</legend>        @helper.inputText(form(name))        @helper.inputFile(form(picture))    <button class=btn btn-primary type=submit>Create</button>    </fieldset>}@for(place <- placesList) {    <p>@(place.name)</p>    <img style=height:200px; src=@routes.Application.getPictureOfPlace(place.name) />}</body>conf/application.conf:play.crypto.secret = changemeplay.i18n.langs = [en]# Enable ReactiveMongoModulemongodb.uri = mongodb://localhost/pictureMinifiedDemoplay.modules.enabled += play.modules.reactivemongo.ReactiveMongoModulemongo-async-driver {  akka {    loglevel = WARNING  }}build.sbt:name := pictureExampleMinifiedversion := 1.0-SNAPSHOTlazy val root = (project in file(.)).enablePlugins(PlayScala)scalaVersion := 2.11.7libraryDependencies ++= Seq(  jdbc,  cache,  ws,  org.reactivemongo %% play2-reactivemongo % 0.11.14,  org.scalatestplus.play %% scalatestplus-play % 1.5.1 % Test)
Simple picture app for storing and viewing
scala;mongodb;rest;nosql