From 05377d023ef4d43818a4b42039c8143cb0f907e4 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Sat, 26 Dec 2020 13:09:41 +0100 Subject: Remove PHPunit integration tests Signed-off-by: Sean Molenaar --- lib/Service/Service.php | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) (limited to 'lib/Service/Service.php') diff --git a/lib/Service/Service.php b/lib/Service/Service.php index 597a99647..ea7c3995d 100644 --- a/lib/Service/Service.php +++ b/lib/Service/Service.php @@ -43,7 +43,7 @@ abstract class Service * @param NewsMapperV2 $mapper * @param LoggerInterface $logger */ - public function __construct($mapper, LoggerInterface $logger) + public function __construct(NewsMapperV2 $mapper, LoggerInterface $logger) { $this->mapper = $mapper; $this->logger = $logger; @@ -76,11 +76,40 @@ abstract class Service * @throws ServiceNotFoundException if the entity does not exist, or there * are more than one of it */ - public function delete(string $userId, int $id) + public function delete(string $userId, int $id): Entity { $entity = $this->find($userId, $id); - $this->mapper->delete($entity); + return $this->mapper->delete($entity); + } + + + /** + * Insert an entity + * + * @param Entity $entity The entity to insert + * + * @return Entity The inserted entity + */ + public function insert(Entity $entity): Entity + { + return $this->mapper->insert($entity); + } + + + /** + * Update an entity + * + * @param string $userId the name of the user for security reasons + * @param Entity $entity the entity + * + * @throws ServiceNotFoundException if the entity does not exist, or there + * are more than one of it + */ + public function update(string $userId, Entity $entity): Entity + { + $this->find($userId, $entity->getId()); + return $this->mapper->update($entity); } @@ -104,4 +133,17 @@ abstract class Service throw new ServiceNotFoundException($ex->getMessage()); } } + + /** + * Delete all items of a user + * + * @param string $userId User ID/name + */ + public function deleteUser(string $userId): void + { + $items = $this->findAllForUser($userId); + foreach ($items as $item) { + $this->mapper->delete($item); + } + } } -- cgit v1.2.3