Implement resolving for specific date via api
This commit is contained in:
@ -120,7 +120,11 @@ function action_get(object $opts) {
|
||||
if (!$collection) {
|
||||
exit_error("Missing collection. Expected: get {collection}");
|
||||
}
|
||||
http_get($collection, [])->then(
|
||||
|
||||
$when = array_shift($opts->args);
|
||||
if ($when) $when = "?date=" . urlencode($when);
|
||||
|
||||
http_get($collection.$when, [])->then(
|
||||
function ($response) {
|
||||
echo $response->getBody()->getContents();
|
||||
},
|
||||
|
@ -116,7 +116,11 @@ class Daemon
|
||||
case null:
|
||||
if ($request->getMethod() == 'GET') {
|
||||
try {
|
||||
$result = $this->opCollectionGet($collectionName);
|
||||
$datetime = $request->getQueryParams()['date']??null;
|
||||
if ($datetime) {
|
||||
$datetime = new DateTime($datetime);
|
||||
}
|
||||
$result = $this->opCollectionGet($collectionName, $datetime);
|
||||
} catch (\Exception $e) {
|
||||
return Response::json([ 'error' => "No such collection" ])->withStatus(404);
|
||||
}
|
||||
@ -163,11 +167,11 @@ class Daemon
|
||||
|
||||
}
|
||||
|
||||
private function opCollectionGet(string $collectionName): array
|
||||
private function opCollectionGet(string $collectionName, ?DateTime $when = null): array
|
||||
{
|
||||
try {
|
||||
$collection = $this->db->getCollection($collectionName);
|
||||
$result = $collection->resolveValues();
|
||||
$result = $collection->resolveValues($when);
|
||||
}
|
||||
catch (\Throwable $t) {
|
||||
throw new \Exception("No such collection");
|
||||
|
Reference in New Issue
Block a user