1
0
mirror of https://github.com/chylex/Nextcloud-News.git synced 2025-05-07 19:34:06 +02:00

rename parameter for read/unread api call

Signed-off-by: Paul Tirk <paultirk@paultirk.com>
This commit is contained in:
Paul Tirk 2022-04-13 15:14:48 +02:00 committed by Benjamin Brahmer
parent 3bdafbfcea
commit da5e749ecc
4 changed files with 44 additions and 10 deletions
appinfo
docs/api
lib/Controller
tests/Unit/Controller

View File

@ -97,8 +97,8 @@ return ['routes' => [
['name' => 'item_api#read', 'url' => '/api/v1-3/items/{itemId}/read', 'verb' => 'POST'], ['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#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_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#read_multiple_by_ids', '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#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#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#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'], ['name' => 'item_api#star_multiple_by_item_ids', 'url' => '/api/v1-3/items/star/multiple', 'verb' => 'POST'],

View File

@ -530,7 +530,7 @@ This is used to stay up to date.
* **Parameters**: * **Parameters**:
```jsonc ```jsonc
{ {
"items": [2, 3] // ids of the items "itemIds": [2, 3] // ids of the items
} }
``` ```
* **Returns**: nothing * **Returns**: nothing
@ -551,7 +551,7 @@ This is used to stay up to date.
* **Parameters**: * **Parameters**:
```jsonc ```jsonc
{ {
"items": [2, 3] // ids of the items "itemIds": [2, 3] // ids of the items
} }
``` ```
* **Returns**: nothing * **Returns**: nothing

View File

@ -323,14 +323,14 @@ class ItemApiController extends ApiController
} }
/** /**
* @param array $items * @param array $itemIds
* @param bool $isRead * @param bool $isRead
* *
* @throws ServiceConflictException * @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 { try {
$this->itemService->read($this->getUserId(), $id, $isRead); $this->itemService->read($this->getUserId(), $id, $isRead);
} catch (ServiceNotFoundException $ex) { } 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 * @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 array $items
* @param bool $isStarred * @param bool $isStarred

View File

@ -398,7 +398,7 @@ class ItemApiControllerTest extends TestCase
[$this->user->getUID(), 2, true], [$this->user->getUID(), 2, true],
[$this->user->getUID(), 4, 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] [$this->user->getUID(), 4, true]
) )
->willReturnOnConsecutiveCalls($this->throwException(new ServiceNotFoundException('')), new Item()); ->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(), 2, false],
[$this->user->getUID(), 4, false] [$this->user->getUID(), 4, false]
); );
$this->class->unreadMultiple([2, 4]); $this->class->unreadMultipleByIds([2, 4]);
} }