Skip to content

Commit

Permalink
Refactor createPinboard method to use pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
HSalaila committed Jul 13, 2016
1 parent 182030e commit 9051dd4
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions app/controllers/RestController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,9 @@ class RestController @Inject() (pinboardRepo: PinboardRepo,
*/
def createPinboard = Action {
request => {
val map = request.body.asFormUrlEncoded
val name = map match {
case Some(map) => map.get("name") match {
case Some(name) => name.head
case None => ""
}
case None => ""
}
val pinboard = name match {
case name if name != "" => pinboardRepo.addPinboard(name)
val nameOpt = request.body.asFormUrlEncoded.map{ case form => form("name").head }
val pinboard = nameOpt match {
case Some(name) if name != "" => pinboardRepo.addPinboard(name)
case _ => pinboardRepo.addPinboard("no name")
}
Ok(Json.toJson(Await.result(pinboard, Duration.Inf))).as("application/json")
Expand Down

0 comments on commit 9051dd4

Please sign in to comment.