summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Tirk <paultirk@paultirk.com>2022-04-13 15:14:48 +0200
committerBenjamin Brahmer <info@b-brahmer.de>2022-04-30 20:04:30 +0200
commitda5e749ecce2a90bc6df8aa52e9e1d7e76ac9efe (patch)
tree3ecdbf291872bb211355c4a3308b04c102644aed
parent3bdafbfcea72ea099836346859f65d5068447eb1 (diff)
rename parameter for read/unread api call
Signed-off-by: Paul Tirk <paultirk@paultirk.com>
-rw-r--r--appinfo/routes.php4
-rw-r--r--docs/api/api-v1-3.md4
-rw-r--r--lib/Controller/ItemApiController.php40
-rw-r--r--tests/Unit/Controller/ItemApiControllerTest.php6
4 files changed, 44 insertions, 10 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 10f2b4fb9..be16ed3bc 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -97,8 +97,8 @@ return ['routes' => [
['name' => 'item_api#read', 'url' => '/api/v1-3/items/{itemId}/read', 'verb' => 'POST'],
['name' => 'item_api#unread', 'url' => '/api/v1-3/items/{itemId}/unread', 'verb' => 'POST'],
['name' => 'item_api#read_all', 'url' => '/api/v1-3/items/read', 'verb' => 'POST'],
-['name' => 'item_api#read_multiple', 'url' => '/api/v1-3/items/read/multiple', 'verb' => 'POST'],
-['name' => 'item_api#unread_multiple', 'url' => '/api/v1-3/items/unread/multiple', 'verb' => 'POST'],
+['name' => 'item_api#read_multiple_by_ids', 'url' => '/api/v1-3/items/read/multiple', 'verb' => 'POST'],
+['name' => 'item_api#unread_multiple_by_ids', 'url' => '/api/v1-3/items/unread/multiple', 'verb' => 'POST'],
['name' => 'item_api#star_by_item_id', 'url' => '/api/v1-3/items/{itemId}/star', 'verb' => 'POST'],
['name' => 'item_api#unstar_by_item_id', 'url' => '/api/v1-3/items/{itemId}/unstar', 'verb' => 'POST'],
['name' => 'item_api#star_multiple_by_item_ids', 'url' => '/api/v1-3/items/star/multiple', 'verb' => 'POST'],
diff --git a/docs/api/api-v1-3.md b/docs/api/api-v1-3.md
index 16317c1f2..4ecd22b95 100644
--- a/docs/api/api-v1-3.md
+++ b/docs/api/api-v1-3.md
@@ -530,7 +530,7 @@ This is used to stay up to date.
* **Parameters**:
```jsonc
{
- "items": [2, 3] // ids of the items
+ "itemIds": [2, 3] // ids of the items
}
```
* **Returns**: nothing
@@ -551,7 +551,7 @@ This is used to stay up to date.
* **Parameters**:
```jsonc
{
- "items": [2, 3] // ids of the items
+ "itemIds": [2, 3] // ids of the items
}
```
* **Returns**: nothing
diff --git a/lib/Controller/ItemApiController.php b/lib/Controller/ItemApiController.php
index 60d5a469a..bdc6e5140 100644
--- a/lib/Controller/ItemApiController.php
+++ b/lib/Controller/ItemApiController.php
@@ -323,14 +323,14 @@ class ItemApiController extends ApiController
}
/**
- * @param array $items
+ * @param array $itemIds
* @param bool $isRead
*
* @throws ServiceConflictException
*/
- private function setMultipleRead(array $items, bool $isRead): void
+ private function setMultipleRead(array $itemIds, bool $isRead): void
{
- foreach ($items as $id) {
+ foreach ($itemIds as $id) {
try {
$this->itemService->read($this->getUserId(), $id, $isRead);
} catch (ServiceNotFoundException $ex) {
@@ -361,6 +361,23 @@ class ItemApiController extends ApiController
/**
* @NoAdminRequired
+ * @NoCSRFRequired
+ * @CORS
+ *
+ * @param int[] $itemIds item ids
+ *
+ * @return void
+ *
+ * @throws ServiceConflictException
+ */
+ public function readMultipleByIds(array $itemIds): void
+ {
+ $this->setMultipleRead($itemIds, true);
+ }
+
+
+ /**
+ * @NoAdminRequired
*
* @NoCSRFRequired
*
@@ -379,6 +396,23 @@ class ItemApiController extends ApiController
/**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @CORS
+ *
+ * @param int[] $itemIds item ids
+ *
+ * @return void
+ *
+ * @throws ServiceConflictException
+ */
+ public function unreadMultipleByIds(array $itemIds): void
+ {
+ $this->setMultipleRead($itemIds, false);
+ }
+
+
+ /**
* @param array $items
* @param bool $isStarred
*
diff --git a/tests/Unit/Controller/ItemApiControllerTest.php b/tests/Unit/Controller/ItemApiControllerTest.php
index 400c4fc32..5359e8972 100644
--- a/tests/Unit/Controller/ItemApiControllerTest.php
+++ b/tests/Unit/Controller/ItemApiControllerTest.php
@@ -398,7 +398,7 @@ class ItemApiControllerTest extends TestCase
[$this->user->getUID(), 2, true],
[$this->user->getUID(), 4, true]
);
- $this->class->readMultiple([2, 4]);
+ $this->class->readMultipleByIds([2, 4]);
}
@@ -411,7 +411,7 @@ class ItemApiControllerTest extends TestCase
[$this->user->getUID(), 4, true]
)
->willReturnOnConsecutiveCalls($this->throwException(new ServiceNotFoundException('')), new Item());
- $this->class->readMultiple([2, 4]);
+ $this->class->readMultipleByIds([2, 4]);
}
@@ -423,7 +423,7 @@ class ItemApiControllerTest extends TestCase
[$this->user->getUID(), 2, false],
[$this->user->getUID(), 4, false]
);
- $this->class->unreadMultiple([2, 4]);
+ $this->class->unreadMultipleByIds([2, 4]);
}