--- a/src/main/scala/Main.scala Thu Aug 25 10:36:04 2011 -0400
+++ b/src/main/scala/Main.scala Thu Aug 25 12:00:40 2011 -0400
@@ -68,7 +68,7 @@
def format(workout:Workout) = {
import workout._
val uri = "%s://%s/user/%s/workout/%s" format (req.underlying.getScheme, host, user, id)
- """{ "activity": "%s", "time": %d, "duration": %d, "distance": %f, "json": "%s", "gpx": "%s" }""" format (activity, 123456789L, 3600000L, 12.0, uri+".json", uri+".gpx")
+ """{ "activity": "%s", "date": %d, "duration": %d, "distance": %f, "json": "%s", "gpx": "%s" }""" format (activity, date, distance, 12.0, uri+".json", uri+".gpx")
}
val jsonResponse = WorkoutDAO.find(ref = MongoDBObject()) map { w => format(w) } mkString ("[ ", ", ", " ]")
Ok ~> ContentType("application/json") ~> ResponseString(jsonResponse)
--- a/src/main/scala/Workout.scala Thu Aug 25 10:36:04 2011 -0400
+++ b/src/main/scala/Workout.scala Thu Aug 25 12:00:40 2011 -0400
@@ -33,12 +33,14 @@
*/
case class Workout(@Key("_id") id: ObjectId = new ObjectId,
- activity:String,
- events:List[Event]) {
+ activity:String,
+ date: Long,
+ distance: Long,
+ events:scala.collection.immutable.Seq[Event]) {
def asJSON:String = {
val formattedEvents = events map { _.asJSON } mkString ("[ ", ", ", " ]")
- """{ "activity": "%s", "events": %s }""" format (activity, formattedEvents)
+ """{ "activity": "%s", "date": %d, "distance": %d, "events": %s }""" format (activity, date, distance, formattedEvents)
}
}
@@ -61,8 +63,8 @@
}
-object WorkoutDAO extends SalatDAO[Workout, ObjectId](collection = MongoConnection("gw42.w3.org", 27017)("virtual_trainer")("user/workouts")) {
-
+object WorkoutDAO extends SalatDAO[Workout, ObjectId](collection = MongoConnection("gw42.w3.org", 27017)("virtual_trainer")("user.workouts")) {
+
def findOneByID(id:String):Option[Workout] = {
try {
val objectId = new ObjectId(id)
--- a/src/test/scala/WorkoutAPISpec.scala Thu Aug 25 10:36:04 2011 -0400
+++ b/src/test/scala/WorkoutAPISpec.scala Thu Aug 25 12:00:40 2011 -0400
@@ -14,7 +14,9 @@
val workout = """
{
- "activity":"http://dbpedia.org/resource/Running",
+ "activity": "http://dbpedia.org/resource/Running",
+ "date": 1314049555595,
+ "distance": 5000,
"events":
[
{