From 26c0cca1a9f58837d7b25fe71270cc811689c35c Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sun, 28 Jan 2018 15:09:22 -0800 Subject: [PATCH] add a route to return the current in-progress trip closes #16 and #15 --- compass/app/Http/Controllers/Api.php | 24 +++++++++++++++++++++++- compass/app/Http/routes.php | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/compass/app/Http/Controllers/Api.php b/compass/app/Http/Controllers/Api.php index 4e0387b..90bddd8 100644 --- a/compass/app/Http/Controllers/Api.php +++ b/compass/app/Http/Controllers/Api.php @@ -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) { diff --git a/compass/app/Http/routes.php b/compass/app/Http/routes.php index 8e91489..f3053d9 100644 --- a/compass/app/Http/routes.php +++ b/compass/app/Http/routes.php @@ -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');