Skip to content

Commit

Permalink
chore: migrate some routes to the new format
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Molenaar <[email protected]>
  • Loading branch information
SMillerDev committed Nov 13, 2024
1 parent bb29359 commit 7cc727f
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ You can also check [on GitHub](https://github.com/nextcloud/news/releases), the
# Unreleased
## [25.x.x]
### Changed
- Migrate routes to new location in the controllers

### Fixed

Expand Down
44 changes: 0 additions & 44 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,60 +15,16 @@

return ['routes' => [
// page
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'page#settings', 'url' => '/settings', 'verb' => 'GET'],
['name' => 'page#update_settings', 'url' => '/settings', 'verb' => 'PUT'],
['name' => 'page#manifest', 'url' => '/manifest.webapp', 'verb' => 'GET'],
['name' => 'page#explore', 'url' => '/explore/feeds.{lang}.json', 'verb' => 'GET'],

// admin
['name' => 'admin#update', 'url' => '/admin', 'verb' => 'PUT'],
['name' => 'admin#migrate', 'url' => '/admin/migrate', 'verb' => 'POST'],

// folders
['name' => 'folder#index', 'url' => '/folders', 'verb' => 'GET'],
['name' => 'folder#create', 'url' => '/folders', 'verb' => 'POST'],
['name' => 'folder#delete', 'url' => '/folders/{folderId}', 'verb' => 'DELETE'],
['name' => 'folder#restore', 'url' => '/folders/{folderId}/restore', 'verb' => 'POST'],
['name' => 'folder#rename', 'url' => '/folders/{folderId}/rename', 'verb' => 'POST'],
['name' => 'folder#read', 'url' => '/folders/{folderId}/read', 'verb' => 'POST'],
['name' => 'folder#open', 'url' => '/folders/{folderId}/open', 'verb' => 'POST'],

// feeds
['name' => 'feed#index', 'url' => '/feeds', 'verb' => 'GET'],
['name' => 'feed#create', 'url' => '/feeds', 'verb' => 'POST'],
['name' => 'feed#delete', 'url' => '/feeds/{feedId}', 'verb' => 'DELETE'],
['name' => 'feed#restore', 'url' => '/feeds/{feedId}/restore', 'verb' => 'POST'],
['name' => 'feed#read', 'url' => '/feeds/{feedId}/read', 'verb' => 'POST'],
['name' => 'feed#update', 'url' => '/feeds/{feedId}/update', 'verb' => 'POST'],
['name' => 'feed#active', 'url' => '/feeds/active', 'verb' => 'GET'],
['name' => 'feed#import', 'url' => '/feeds/import/articles', 'verb' => 'POST'],
['name' => 'feed#patch', 'url' => '/feeds/{feedId}', 'verb' => 'PATCH'],

// items
['name' => 'item#index', 'url' => '/items', 'verb' => 'GET'],
['name' => 'item#new_items', 'url' => '/items/new', 'verb' => 'GET'],
['name' => 'item#readAll', 'url' => '/items/read', 'verb' => 'POST'],
['name' => 'item#read', 'url' => '/items/{itemId}/read', 'verb' => 'POST'],
['name' => 'item#read_multiple', 'url' => '/items/read/multiple', 'verb' => 'POST'],
['name' => 'item#star', 'url' => '/items/{feedId}/{guidHash}/star', 'verb' => 'POST'],
['name' => 'item#share', 'url' => '/items/{itemId}/share/{shareRecipientId}', 'verb' => 'POST'],

// export
['name' => 'export#opml', 'url' => '/export/opml', 'verb' => 'GET'],
['name' => 'export#articles', 'url' => '/export/articles', 'verb' => 'GET'],

// general API
['name' => 'api#index', 'url' => '/api', 'verb' => 'GET'],

['name' => 'utility_api#preflighted_cors', 'url' => '/api/{apiVersion}/{path}', 'verb' => 'OPTIONS', 'requirements' => ['apiVersion' => 'v(1-[23]|2)', 'path' => '.+']],
['name' => 'utility_api#version', 'url' => '/api/{apiVersion}/version', 'verb' => 'GET', 'requirements' => ['apiVersion' => 'v(1-[23]|2)']],

// API 1.x
['name' => 'utility_api#status', 'url' => '/api/{apiVersion}/status', 'verb' => 'GET', 'requirements' => ['apiVersion' => 'v1-[23]']],
['name' => 'utility_api#before_update', 'url' => '/api/{apiVersion}/cleanup/before-update', 'verb' => 'GET', 'requirements' => ['apiVersion' => 'v1-[23]']],
['name' => 'utility_api#after_update', 'url' => '/api/{apiVersion}/cleanup/after-update', 'verb' => 'GET', 'requirements' => ['apiVersion' => 'v1-[23]']],

// folders
['name' => 'folder_api#index', 'url' => '/api/{apiVersion}/folders', 'verb' => 'GET', 'requirements' => ['apiVersion' => 'v1-[23]']],
['name' => 'folder_api#create', 'url' => '/api/{apiVersion}/folders', 'verb' => 'POST', 'requirements' => ['apiVersion' => 'v1-[23]']],
Expand Down
2 changes: 2 additions & 0 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OCP\AppFramework\Http\Attribute\CORS;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\Attribute\ApiRoute;

/**
* Class ApiController
Expand Down Expand Up @@ -75,6 +76,7 @@ protected function getUserId()
#[CORS]
#[NoCSRFRequired]
#[PublicPage]
#[ApiRoute(verb: 'GET', url: '/api')]
public function index(): array
{
return [
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function getUser(): ?IUser
/**
* @return string
*/
protected function getUserId()
protected function getUserId(): string
{
return $this->getUser()->getUID();
}
Expand Down
5 changes: 4 additions & 1 deletion lib/Controller/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
use OCP\IUserSession;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\CORS;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;


/**
* Class ExportController
Expand All @@ -47,6 +48,7 @@ public function __construct(

#[NoCSRFRequired]
#[NoAdminRequired]
#[FrontpageRoute(verb: 'GET', url: '/export/opml')]
public function opml(): DataDownloadResponse
{
$date = date('Y-m-d');
Expand All @@ -61,6 +63,7 @@ public function opml(): DataDownloadResponse

#[NoCSRFRequired]
#[NoAdminRequired]
#[FrontpageRoute(verb: 'GET', url: '/export/articles')]
public function articles(): JSONResponse
{
$feeds = $this->feedService->findAllForUser($this->getUserId());
Expand Down
10 changes: 10 additions & 0 deletions lib/Controller/FeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use OCP\IConfig;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;

use OCA\News\Db\ListType;
use OCP\IUserSession;
Expand All @@ -46,6 +47,7 @@ public function __construct(


#[NoAdminRequired]
#[FrontpageRoute(verb: 'GET', url: '/feeds')]
public function index(): array
{

Expand All @@ -72,6 +74,7 @@ public function index(): array


#[NoAdminRequired]
#[FrontpageRoute(verb: 'GET', url: '/feeds/active')]
public function active(): array
{
$feedId = (int) $this->settings->getUserValue(
Expand Down Expand Up @@ -126,6 +129,7 @@ public function active(): array
* @return array|JSONResponse
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'POST', url: '/feeds')]
public function create(
string $url,
?int $parentFolderId,
Expand Down Expand Up @@ -180,6 +184,7 @@ public function create(
* @return array|JSONResponse
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'DELETE', url: '/feeds/{feedId}')]
public function delete(int $feedId)
{
try {
Expand All @@ -200,6 +205,7 @@ public function delete(int $feedId)
* @return array|JSONResponse
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'POST', url: '/feeds/{feedId}/update')]
public function update(int $feedId)
{
try {
Expand Down Expand Up @@ -227,6 +233,7 @@ public function update(int $feedId)
* @return array
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'POST', url: '/feeds/import/articles')]
public function import(array $json): array
{
$feed = $this->importService->importArticles($this->getUserId(), $json);
Expand All @@ -249,6 +256,7 @@ public function import(array $json): array
* @return array
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'POST', url: '/feeds/{feedId}/read')]
public function read(int $feedId, int $highestItemId): array
{
$this->feedService->read($this->getUserId(), $feedId, $highestItemId);
Expand All @@ -270,6 +278,7 @@ public function read(int $feedId, int $highestItemId): array
* @return array|JSONResponse
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'POST', url: '/feeds/{feedId}/restore')]
public function restore(int $feedId)
{
try {
Expand All @@ -295,6 +304,7 @@ public function restore(int $feedId)
* @return array|JSONResponse
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'PATCH', url: '/feeds/{feedId}')]
public function patch(
int $feedId,
?bool $pinned = null,
Expand Down
8 changes: 8 additions & 0 deletions lib/Controller/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use \OCP\IRequest;
use \OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;

use \OCA\News\Service\FolderServiceV2;
use \OCA\News\Service\Exceptions\ServiceNotFoundException;
Expand All @@ -43,6 +44,7 @@ public function __construct(
* @psalm-return array{folders: array}
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'GET', url: '/folders')]
public function index(): array
{
$folders = $this->folderService->findAllForUser($this->getUserId());
Expand All @@ -57,6 +59,7 @@ public function index(): array
* @return array|JSONResponse
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'POST', url: '/folders/{folderId}/open')]
public function open(?int $folderId, bool $open)
{
$folderId = $folderId === 0 ? null : $folderId;
Expand All @@ -78,6 +81,7 @@ public function open(?int $folderId, bool $open)
* @return array|JSONResponse
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'POST', url: '/folders')]
public function create(string $folderName, ?int $parent = null)
{
$this->folderService->purgeDeleted($this->getUserId(), time() - 600);
Expand All @@ -93,6 +97,7 @@ public function create(string $folderName, ?int $parent = null)
* @return array|JSONResponse
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'DELETE', url: '/folders/{folderId}')]
public function delete(?int $folderId)
{
if (is_null($folderId)) {
Expand All @@ -117,6 +122,7 @@ public function delete(?int $folderId)
* @return array|JSONResponse
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'POST', url: '/folders/{folderId}/rename')]
public function rename(?int $folderId, string $folderName)
{
if (is_null($folderId)) {
Expand All @@ -143,6 +149,7 @@ public function rename(?int $folderId, string $folderName)
* @throws ServiceNotFoundException
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'POST', url: '/folders/{folderId}/read')]
public function read(?int $folderId, int $maxItemId): void
{
$folderId = $folderId === 0 ? null : $folderId;
Expand All @@ -157,6 +164,7 @@ public function read(?int $folderId, int $maxItemId): void
* @return array|JSONResponse
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'POST', url: '/folders/{folderId}/restore')]
public function restore(?int $folderId)
{
$folderId = $folderId === 0 ? null : $folderId;
Expand Down
8 changes: 8 additions & 0 deletions lib/Controller/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use \OCP\IConfig;
use \OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;

use \OCA\News\Service\Exceptions\ServiceException;
use \OCA\News\Service\Exceptions\ServiceNotFoundException;
Expand Down Expand Up @@ -64,6 +65,7 @@ public function __construct(
* @return array
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'GET', url: '/items')]
public function index(
int $type = 3,
int $id = 0,
Expand Down Expand Up @@ -184,6 +186,7 @@ public function index(
* @return array
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'GET', url: '/items/new')]
public function newItems(int $type, int $id, $lastModified = 0): array
{
$showAll = $this->settings->getUserValue(
Expand Down Expand Up @@ -245,6 +248,7 @@ public function newItems(int $type, int $id, $lastModified = 0): array
* @return array|JSONResponse
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'POST', url: '/items/{feedId}/{guidHash}/star')]
public function star(int $feedId, string $guidHash, bool $isStarred)
{
try {
Expand All @@ -269,6 +273,7 @@ public function star(int $feedId, string $guidHash, bool $isStarred)
* @return array|JSONResponse
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'POST', url: '/items/{itemId}/read')]
public function read(int $itemId, $isRead = true)
{
try {
Expand All @@ -287,6 +292,7 @@ public function read(int $itemId, $isRead = true)
* @return array
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'POST', url: '/items/read')]
public function readAll(int $highestItemId): array
{
$this->itemService->readAll($this->getUserId(), $highestItemId);
Expand All @@ -300,6 +306,7 @@ public function readAll(int $highestItemId): array
* @return void
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'POST', url: '/items/read/multiple')]
public function readMultiple(array $itemIds): void
{
foreach ($itemIds as $id) {
Expand All @@ -317,6 +324,7 @@ public function readMultiple(array $itemIds): void
* @param string $shareRecipientId User to share the item with
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'POST', url: '/items/{itemId}/share/{shareRecipientId}')]
public function share(int $itemId, string $shareRecipientId)
{
try {
Expand Down
5 changes: 5 additions & 0 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCP\AppFramework\Services\IInitialState;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;

use OCA\News\Service\StatusService;
use OCA\News\Explore\RecommendedSites;
Expand All @@ -53,6 +54,7 @@ public function __construct(

#[NoCSRFRequired]
#[NoAdminRequired]
#[FrontpageRoute(verb: 'GET', url: '/')]
public function index(): TemplateResponse
{
$status = $this->statusService->getStatus();
Expand Down Expand Up @@ -110,6 +112,7 @@ public function index(): TemplateResponse
}

#[NoAdminRequired]
#[FrontpageRoute(verb: 'GET', url: '/settings')]
public function settings(): array
{
$settings = [
Expand Down Expand Up @@ -159,6 +162,7 @@ public function settings(): array
* @param bool $disableRefresh
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'PUT', url: '/settings')]
public function updateSettings(
bool $showAll,
bool $compact,
Expand Down Expand Up @@ -193,6 +197,7 @@ public function updateSettings(
* @return Http\JSONResponse|array
*/
#[NoAdminRequired]
#[FrontpageRoute(verb: 'GET', url: '/explore/feeds.{lang}.json')]
public function explore(string $lang)
{
$this->config->setUserValue(
Expand Down
Loading

0 comments on commit 7cc727f

Please sign in to comment.