summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/ApiController.php2
-rw-r--r--lib/Controller/ItemApiController.php51
-rw-r--r--lib/Service/ItemServiceV2.php26
3 files changed, 78 insertions, 1 deletions
diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php
index 35924c261..c965dead5 100644
--- a/lib/Controller/ApiController.php
+++ b/lib/Controller/ApiController.php
@@ -82,7 +82,7 @@ class ApiController extends BaseApiController
public function index(): array
{
return [
- 'apiLevels' => ['v1-2', 'v2']
+ 'apiLevels' => ['v1-2', 'v1-3', 'v2']
];
}
}
diff --git a/lib/Controller/ItemApiController.php b/lib/Controller/ItemApiController.php
index 2e59d5b3a..dec04bbe6 100644
--- a/lib/Controller/ItemApiController.php
+++ b/lib/Controller/ItemApiController.php
@@ -222,6 +222,25 @@ class ItemApiController extends ApiController
/**
+ * @param int $itemId
+ * @param bool $isStarred
+ *
+ * @return array|JSONResponse
+ * @throws ServiceConflictException
+ */
+ private function setStarredByItemId(int $itemId, bool $isStarred)
+ {
+ try {
+ $this->itemService->starByItemId($this->getUserId(), $itemId, $isStarred);
+ } catch (ServiceNotFoundException $ex) {
+ return $this->error($ex, Http::STATUS_NOT_FOUND);
+ }
+
+ return [];
+ }
+
+
+ /**
* @NoAdminRequired
* @NoCSRFRequired
* @CORS
@@ -257,6 +276,38 @@ class ItemApiController extends ApiController
/**
* @NoAdminRequired
+ * @NoCSRFRequired
+ * @CORS
+ *
+ * @param int $itemId
+ *
+ * @return array|JSONResponse
+ * @throws ServiceConflictException
+ */
+ public function starByItemId(int $itemId)
+ {
+ return $this->setStarredByItemId($itemId, true);
+ }
+
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @CORS
+ *
+ * @param int $itemId
+ *
+ * @return array|JSONResponse
+ * @throws ServiceConflictException
+ */
+ public function unstarByItemId(int $itemId)
+ {
+ return $this->setStarredByItemId($itemId, false);
+ }
+
+
+ /**
+ * @NoAdminRequired
*
* @NoCSRFRequired
*
diff --git a/lib/Service/ItemServiceV2.php b/lib/Service/ItemServiceV2.php
index 57804a8c3..4f314105b 100644
--- a/lib/Service/ItemServiceV2.php
+++ b/lib/Service/ItemServiceV2.php
@@ -212,6 +212,32 @@ class ItemServiceV2 extends Service
}
/**
+ * Mark an item as starred by id
+ *
+ * @param string $userId Item owner
+ * @param int $itemId
+ * @param bool $starred
+ *
+ * @return Item
+ * @throws ServiceConflictException
+ * @throws ServiceNotFoundException
+ */
+ public function starByItemId(string $userId, int $itemId, bool $starred): Entity
+ {
+ try {
+ $item = $this->mapper->findFromUser($userId, $itemId);
+ } catch (DoesNotExistException $ex) {
+ throw ServiceNotFoundException::from($ex);
+ } catch (MultipleObjectsReturnedException $ex) {
+ throw ServiceConflictException::from($ex);
+ }
+
+ $item->setStarred($starred);
+
+ return $this->mapper->update($item);
+ }
+
+ /**
* Mark all items as read
*
* @param string $userId Item owner