How an application built on Scala Play Framework is helping outdoor enthusiasts
A ScalaSyd presentation by Chris Cooper
http://chris-cooper.github.io/doarama-scala-syd/
Hmmm
Upload / Live |
Correlate | Tweak | Share | Comment |
What we have...
|
What's missing...
|
Sidney Shek / Clinton Freeman / Mark Hibberd / Eric Torreborre / Tony Morris
FP / Scala / Web / scoobi / specs2 etc..
$ git push heroku master
dev | stage | production
Website | Shared | API | ||
Controllers / Views | Models / Services | Controllers / Views | ||
def listByUserId(user_id: Long, page: Int = 0, pageSize: Int = 10): Page[ActivityWithVisualisations] = {
val offset = pageSize * page
DB.withConnection { implicit connection =>
val items = SQL(
"""
select * from activity
left join activitytype on activity.activitytype_id = activitytype.id
where user_id = {user_id}
order by activity.id desc
limit {pageSize} offset {offset}
""").on(
'user_id -> user_id,
'pageSize -> pageSize,
'offset -> offset).as(Activity.withType2 *)
...
}
}
def list(page: Int) = SecuredAction { implicit request =>
val user = Users.getUser(request.user)
val activities = Activity.listByUserId(user.id, page)
Ok(views.html.activities(Some(user), activities))
}
@activities.map { case activity =>
@activity.label
@activity.location
@activity.activityType.name
...
}
"create an activity" in {
val requestStr = "{...}"
val request = FakeRequest(POST, "/api/0.2/livetrack/activity", requestHeader, Json.parse(requestStr))
val result = route(request).get
status(result) must equalTo(OK)
val resultJson = Json.parse(contentAsString(result))
resultJson.asOpt[IdResult] must beSome[IdResult]
July 2013 -> March 2014 (now)