Skip to content

Commit

Permalink
SlimLocation supports Optional addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
KatrinaHoffert committed Mar 10, 2015
1 parent ae75ed8 commit 9df672e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/models/Location.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ object Location {
}

query().map {
row => SlimLocation(row[Int]("id"), row[String]("name"), row[String]("address"))
row => SlimLocation(row[Int]("id"), row[String]("name"), row[Option[String]]("address"))
}.toList
}
}
Expand Down Expand Up @@ -161,4 +161,4 @@ object Location {
* A slimmed down version of the Location class used to represent the data we need when selecting
* a location.
*/
case class SlimLocation(id: Int, name: String, address: String)
case class SlimLocation(id: Int, name: String, address: Option[String])
4 changes: 3 additions & 1 deletion app/util/TypeConversions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package util
import models._
import scala.util.{Try, Success, Failure}
import play.api.libs.json._
import play.api.i18n.Messages

/**
* Contains methods for performing and simplifying type conversions.
Expand All @@ -23,9 +24,10 @@ object TypeConversions {
*/
def slimLocationsToJson(locations: Seq[SlimLocation]): JsValue = {
val jsObjects = locations.map { location =>
val address = location.address.getOrElse(Messages("errors.unknownAddress"))
Json.obj(
"name" -> location.name,
"address" -> location.address,
"address" -> address,
"id" -> location.id
)
}
Expand Down
1 change: 1 addition & 0 deletions conf/messages.en
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ errors.emptyCityTitle=There's no locations in this city
errors.emptyCityDesc=Uh oh...
errors.emptyCityText=There''s no locations in "{0}". Perhaps you''ve mistyped a URL or there''s a bug in our software.
errors.emptyCityTryAgain=Give the city selection another try?
errors.unknownAddress=Unknown address

0 comments on commit 9df672e

Please sign in to comment.