From da5e749ecce2a90bc6df8aa52e9e1d7e76ac9efe Mon Sep 17 00:00:00 2001 From: Paul Tirk Date: Wed, 13 Apr 2022 15:14:48 +0200 Subject: rename parameter for read/unread api call Signed-off-by: Paul Tirk --- appinfo/routes.php | 4 +-- docs/api/api-v1-3.md | 4 +-- lib/Controller/ItemApiController.php | 40 +++++++++++++++++++++++-- tests/Unit/Controller/ItemApiControllerTest.php | 6 ++-- 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) { @@ -359,6 +359,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 * @@ -378,6 +395,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]); } -- cgit v1.2.3