Add group management methods

This commit is contained in:
2025-03-13 19:11:29 +01:00
parent 43d5db56cf
commit f3d6e3e7b3

View File

@ -25,6 +25,14 @@ class SlotDbClient
return $this->client->sendRequest($request); 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 private function post(string $path, array $data, array $query = [], array $headers = []): ResponseInterface
{ {
$queryStr = \http_build_query($query); $queryStr = \http_build_query($query);
@ -34,6 +42,12 @@ class SlotDbClient
return $this->client->sendRequest($request); return $this->client->sendRequest($request);
} }
/**
* Retrieve properties for the slot $slotId
*
* @param string $slotId
* @return array<string,mixed>
*/
public function querySlot(string $slotId): array public function querySlot(string $slotId): array
{ {
$res = $this->get("/slot/{$slotId}"); $res = $this->get("/slot/{$slotId}");
@ -41,6 +55,12 @@ class SlotDbClient
return $data; return $data;
} }
/**
* Update properties for the slot $slotId, return new properties
*
* @param string $slotId
* @return array<string,mixed>
*/
public function updateSlot(string $slotId, array $props): array public function updateSlot(string $slotId, array $props): array
{ {
$res = $this->post("/slot/{$slotId}", data: $props); $res = $this->post("/slot/{$slotId}", data: $props);
@ -48,6 +68,15 @@ class SlotDbClient
return $data; return $data;
} }
/**
* Find slots, optionally matching conditions
*
* @param array<string,mixed> $where
* @param array<int,string> $what
* @param int $limit
* @param int $page
* @return array<string,mixed>
*/
public function findSlots(array $where = [], array $what = [], int $limit = 250, int $page = 0): array public function findSlots(array $where = [], array $what = [], int $limit = 250, int $page = 0): array
{ {
$query = [ $query = [
@ -64,4 +93,64 @@ class SlotDbClient
return $data; 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<string,mixed>
*/
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<int,string>
*/
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");
}
} }