summaryrefslogtreecommitdiffstats
path: root/lib/Service/Service.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Service/Service.php')
-rw-r--r--lib/Service/Service.php48
1 files changed, 45 insertions, 3 deletions
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);
+ }
+ }
}