From eb7c1cb2982b0dcc243517ed35d5ca3da2763595 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Sat, 28 Sep 2024 23:33:39 +0200 Subject: [PATCH] Implement resolving for specific date via api --- bin/paramcli | 6 +++++- src/Daemon.php | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/bin/paramcli b/bin/paramcli index 80fa649..91f24ae 100755 --- a/bin/paramcli +++ b/bin/paramcli @@ -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(); }, diff --git a/src/Daemon.php b/src/Daemon.php index 374a832..598ab56 100644 --- a/src/Daemon.php +++ b/src/Daemon.php @@ -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");