Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements for API v1.2 #1727

Merged
merged 10 commits into from
Apr 30, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is mostly based on [Keep a Changelog](https://keepachangelog.com/en/1
# Unreleased
## [18.x.x]
### Changed
- Add routes for starring/unstarring items by id

### Fixed

Expand Down
5 changes: 5 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
['name' => 'folder_api_v2#update', 'url' => '/api/v2/folders/{folderId}', 'verb' => 'PATCH'],
['name' => 'folder_api_v2#delete', 'url' => '/api/v2/folders/{folderId}', 'verb' => 'DELETE'],

// API 1.3
powerpaul17 marked this conversation as resolved.
Show resolved Hide resolved

['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'],

// API 1.2
['name' => 'utility_api#version', 'url' => '/api/v1-2/version', 'verb' => 'GET'],
['name' => 'utility_api#status', 'url' => '/api/v1-2/status', 'verb' => 'GET'],
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function getUserId()
public function index(): array
{
return [
'apiLevels' => ['v1-2', 'v2']
'apiLevels' => ['v1-2', 'v1-3', 'v2']
];
}
}
51 changes: 51 additions & 0 deletions lib/Controller/ItemApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,25 @@ private function setStarred(int $feedId, string $guidHash, bool $isStarred)
}


/**
* @param int $itemId
* @param bool $isStarred
*
* @return array|JSONResponse
* @throws ServiceConflictException
*/
private function setStarredByItemId(int $itemId, bool $isStarred)
{
try {
$this->itemService->star($this->getUserId(), $itemId, $isStarred);
} catch (ServiceNotFoundException $ex) {
return $this->error($ex, Http::STATUS_NOT_FOUND);
}

return [];
}


/**
* @NoAdminRequired
* @NoCSRFRequired
Expand Down Expand Up @@ -255,6 +274,38 @@ public function unstar(int $feedId, string $guidHash)
}


/**
* @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
*
Expand Down
18 changes: 18 additions & 0 deletions tests/Unit/Controller/ItemApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,4 +499,22 @@ public function testUnstarMultiple()
}


public function testStarByItemId()
{
$this->itemService->expects($this->once())
->method('star')
->with($this->uid, 123, true);

$this->class->starByItemId(123);
}


public function testUnstarByItemId()
{
$this->itemService->expects($this->once())
->method('star')
->with($this->uid, 123, false);

$this->class->unstarByItemId(123);
}
}