From f3d6e3e7b3a8daa3111e27407f13ba8c56bf997f Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Thu, 13 Mar 2025 19:11:29 +0100 Subject: [PATCH] Add group management methods --- src/SlotDbClient.php | 89 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/src/SlotDbClient.php b/src/SlotDbClient.php index a9a9d74..71ebebd 100644 --- a/src/SlotDbClient.php +++ b/src/SlotDbClient.php @@ -25,6 +25,14 @@ class SlotDbClient return $this->client->sendRequest($request); } + private function delete(string $path, array $query = [], array $headers = []): ResponseInterface + { + $queryStr = \http_build_query($query); + $fullPath = $this->server . '/api/slotdb/v1/' . ltrim($path, '/') . '?' . $queryStr; + $request = new Request('DELETE', $fullPath, $headers); + return $this->client->sendRequest($request); + } + private function post(string $path, array $data, array $query = [], array $headers = []): ResponseInterface { $queryStr = \http_build_query($query); @@ -34,6 +42,12 @@ class SlotDbClient return $this->client->sendRequest($request); } + /** + * Retrieve properties for the slot $slotId + * + * @param string $slotId + * @return array + */ public function querySlot(string $slotId): array { $res = $this->get("/slot/{$slotId}"); @@ -41,6 +55,12 @@ class SlotDbClient return $data; } + /** + * Update properties for the slot $slotId, return new properties + * + * @param string $slotId + * @return array + */ public function updateSlot(string $slotId, array $props): array { $res = $this->post("/slot/{$slotId}", data: $props); @@ -48,6 +68,15 @@ class SlotDbClient return $data; } + /** + * Find slots, optionally matching conditions + * + * @param array $where + * @param array $what + * @param int $limit + * @param int $page + * @return array + */ public function findSlots(array $where = [], array $what = [], int $limit = 250, int $page = 0): array { $query = [ @@ -64,4 +93,64 @@ class SlotDbClient return $data; } + /** + * Delete a slot + * + * @param string $slotId + * @return void + */ + public function deleteSlot(string $slotId): void + { + $this->delete("/slot/{$slotId}"); + } + + public function findGroups(): array + { + $res = $this->get("/groups"); + $data = json_decode($res->getBody(), true); + return $data; + } + + /** + * Return properties for $groupId + * + * @param string $groupId + * @return array + */ + public function queryGroup(string $groupId): array + { + throw new \Exception("Not implemented"); + } + + public function updateGroup(string $groupId, array $props): array + { + throw new \Exception("Not implemented"); + } + + public function deleteGroup(string $groupId): void + { + throw new \Exception("Not implemented"); + } + + /** + * Return the slots that are members of $groupId + * + * @param string $groupId + * @return array + */ + public function getGroupMembers(string $groupId): array + { + throw new \Exception("Not implemented"); + } + + public function addGroupMembers(string $groupId, array $slots): void + { + throw new \Exception("Not implemented"); + } + + public function removeGroupMembers(string $groupId, array $slots): void + { + throw new \Exception("Not implemented"); + } + }