Implement resolving for specific date via api

This commit is contained in:
2024-09-28 23:33:39 +02:00
parent 593c5d647c
commit eb7c1cb298
2 changed files with 12 additions and 4 deletions

View File

@ -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();
},

View File

@ -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");