Permalink
Browse files

Add journeys route (currently returning JSON)

  • Loading branch information...
1 parent 414585f commit 58e8560406b52c995a90786eabf4f25333c0b21d @kynan kynan committed Oct 13, 2012
Showing with 17 additions and 2 deletions.
  1. +5 −2 models.coffee
  2. +12 −0 routes.coffee
View
@@ -24,14 +24,17 @@ JourneySchema = new mongoose.Schema
name: String
time: Date
users: [{type: mongoose.Schema.ObjectId, ref: 'User'}]
- trainID: String
- location: Array
+ trainId: String
+ location: [Number, Number]
scheduleId: String
terminated: Boolean
route:
type: mongoose.Schema.ObjectId
ref: 'Route'
+JourneySchema.index
+ location: '2d'
+
LocationSchema = new mongoose.Schema
name: String
location:
View
@@ -1,8 +1,20 @@
passport = require 'passport'
+models = require './models'
@include = ->
@get '/': ->
@render 'landing': {passport: @session.passport}
+ @get '/journeys': ->
+ lat = @request.query.lat or -2.009
+ lon = @request.query.lon or 53.73
+ models.journey.find({ location : { $near : [lat,lon] } })
+ .limit(10)
+ .exec (err, journeys) =>
+ if err
+ throw err
+ else
+ @response.json journeys
+
@get '/env': -> @response.json process.env
# Authenication

0 comments on commit 58e8560

Please sign in to comment.