Browse Source

add a route to return the current in-progress trip

closes #16 and #15
pull/23/head
Aaron Parecki 6 years ago
parent
commit
26c0cca1a9
No known key found for this signature in database GPG Key ID: 276C2817346D6056
2 changed files with 24 additions and 1 deletions
  1. +23
    -1
      compass/app/Http/Controllers/Api.php
  2. +1
    -0
      compass/app/Http/routes.php

+ 23
- 1
compass/app/Http/Controllers/Api.php View File

@ -209,7 +209,29 @@ class Api extends BaseController
}
}
return response(json_encode($response))->header('Content-Type', 'application/json');;
return response(json_encode($response))->header('Content-Type', 'application/json');
}
public function trip(Request $request) {
$token = $request->input('token');
if(!$token)
return response(json_encode(['error' => 'no token provided']))->header('Content-Type', 'application/json');
$db = DB::table('databases')->where('read_token','=',$token)->first();
if(!$db)
return response(json_encode(['error' => 'invalid token']))->header('Content-Type', 'application/json');
if($db->current_trip) {
$response = [
'trip' => json_decode($db->current_trip)
];
} else {
$response = [
'trip' => null
];
}
return response(json_encode($response))->header('Content-Type', 'application/json');
}
public function input(Request $request) {

+ 1
- 0
compass/app/Http/routes.php View File

@ -17,6 +17,7 @@ $app->post('/database/create', 'Controller@createDatabase');
$app->get('/api/query', 'Api@query');
$app->get('/api/last', 'Api@last');
$app->get('/api/trip', 'Api@trip');
$app->get('/api/find-from-localtime', 'LocalTime@find');
$app->get('/api/input', 'Api@account');
$app->post('/api/input', 'Api@input');

Loading…
Cancel
Save