From bb3ff4493ac23ec9af296693e1f4dd3795f98b27 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sun, 10 Jan 2016 13:02:22 -0800 Subject: [PATCH] support `/api/last` with no date --- README.md | 2 +- compass/app/Http/Controllers/Api.php | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 34419b6..6a58ea3 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ To read a database, make a GET request as follows: `GET /api/last` * token - (required) the read token for the database * tz - (optional, default UTC) timezone string (e.g. America/Los_Angeles) which will be used to determine the absolute start/end times for the day -* date - (optional) specify a full timestamp to return a single record before this date (the point returned will be no more than 24 hours before the given date) +* date - (optional, default to now) specify a full timestamp to return a single record before this date (the point returned will be no more than 24 hours before the given date) * geocode - (optional) if "true", then the location found will be reverse geocoded using [Atlas](https://atlas.p3k.io) to find the city and timezone at the location diff --git a/compass/app/Http/Controllers/Api.php b/compass/app/Http/Controllers/Api.php index 059c720..fd0e623 100644 --- a/compass/app/Http/Controllers/Api.php +++ b/compass/app/Http/Controllers/Api.php @@ -137,9 +137,10 @@ class Api extends BaseController return response(json_encode(['error' => 'invalid date provided']))->header('Content-Type', 'application/json'); } } else { - return response(json_encode(['error' => 'no date provided']))->header('Content-Type', 'application/json'); + $date = new DateTime(); } + /* ********************************************** */ // TODO: move this logic into QuartzDB // Load the shard for the given date @@ -164,6 +165,13 @@ class Api extends BaseController break; $record = $r; } + /* ********************************************** */ + + if(!$record) { + return response(json_encode([ + 'data'=>null + ])); + } $response = [ 'data' => $record->data