From 9187acfc47118be6a55b1b8b4089475303cac71f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 13 Nov 2018 15:30:48 +0100 Subject: [PATCH] Add method to get actor by id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Db/ActorsRequest.php | 20 ++++++++++++++++++++ lib/Service/ActorService.php | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/lib/Db/ActorsRequest.php b/lib/Db/ActorsRequest.php index ebcf006f..d041d06f 100644 --- a/lib/Db/ActorsRequest.php +++ b/lib/Db/ActorsRequest.php @@ -109,6 +109,26 @@ class ActorsRequest extends ActorsRequestBuilder { return $this->parseActorsSelectSql($data); } + /** + * @param string $username + * @return Person + * @throws ActorDoesNotExistException + */ + public function getFromId(string $id): Person { + $qb = $this->getActorsSelectSql(); + $this->limitToIdString($qb, $id); + + $cursor = $qb->execute(); + $data = $cursor->fetch(); + $cursor->closeCursor(); + + if ($data === false) { + throw new ActorDoesNotExistException('Actor not found'); + } + + return $this->parseActorsSelectSql($data); + } + /** * return Actor from database, based on the userId of the owner. diff --git a/lib/Service/ActorService.php b/lib/Service/ActorService.php index 0e9ea183..f7730c1c 100644 --- a/lib/Service/ActorService.php +++ b/lib/Service/ActorService.php @@ -90,6 +90,12 @@ class ActorService { return $actor; } + public function getActorById(string $id): Person { + $actor = $this->actorsRequest->getFromId($id); + + return $actor; + } + /** * @param string $userId