Browse Source

support `/api/last` with no date

pull/5/head
Aaron Parecki 9 years ago
parent
commit
bb3ff4493a
2 changed files with 10 additions and 2 deletions
  1. +1
    -1
      README.md
  2. +9
    -1
      compass/app/Http/Controllers/Api.php

+ 1
- 1
README.md View File

@ -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

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

@ -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

Loading…
Cancel
Save