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
nextcloud-bot authored and SMillerDev committed Nov 16, 2024
1 parent 88757eb commit f7a2959
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 40 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ You can also check [on GitHub](https://github.com/nextcloud/news/releases), the
## [25.x.x]
### Changed
- If title of feed is empty during creation set hostname of feed as title (#2872)
- Migrate routes to new location in the controllers

### Fixed
- Feed without Title returned by DB causes exception (#2872)
Expand Down
38 changes: 0 additions & 38 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,14 @@

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

Expand Down
4 changes: 4 additions & 0 deletions l10n/sk.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ OC.L10N.register(
"Interval in seconds in which the feeds will be updated." : "Interval v sekundách, počas ktorého sa kanály aktualizujú.",
"No article selected" : "Žiadny článok nebol vybraný.",
"Please select an article from the list..." : "Vyberte prosím článok zo zoznamu...",
"Move feed to folder" : "Presunúť kanál do priečinka",
"Move" : "Presunúť",
"User Name" : "Úžívateľské meno",
"Share" : "Zdieľať",
Expand All @@ -56,12 +57,14 @@ OC.L10N.register(
"Mark read" : "Označ ako prečítané",
"All articles" : "Všetky články",
"Starred" : "S hviezdičkou",
"Has feeds with errors!" : "Má kanály s chybami!",
"Explore" : "Preskúmať",
"Settings" : "Nastavenia",
"Keyboard shortcuts" : "Klávesové skratky",
"Disable mark read through scrolling" : "Vypnúť označovanie ako prečítané pri posune",
"Show all articles" : "Zobraziť všetky články",
"Reverse ordering (oldest on top)" : "Opačné zoradenie (od najstarších)",
"Disable automatic refresh" : "Zakázať automatické obnovenie",
"Are you sure you want to mark all read?" : "Ste si istý, že chcete označiť všetko ako prečítané?",
"Rename Folder" : "Premenovať Priečinok",
"Are you sure you want to delete?" : "Naozaj chcete vymazať?",
Expand Down Expand Up @@ -111,6 +114,7 @@ OC.L10N.register(
"Load next folder" : "Načítať ďalší priečinok",
"Scroll to active navigation entry" : "Posunte na aktiváciu položky menu",
"Shift" : "Shift",
"Mark current articles feed/folder as read" : "Označiť aktuálny kanál/priečinok s článkami ako prečítaný",
"All Articles" : "Všetky články",
"No feeds found to add" : "Žiadne kanály na pridanie neboli nájdené.",
"Subscribe to" : "Odobrať z",
Expand Down
4 changes: 4 additions & 0 deletions l10n/sk.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"Interval in seconds in which the feeds will be updated." : "Interval v sekundách, počas ktorého sa kanály aktualizujú.",
"No article selected" : "Žiadny článok nebol vybraný.",
"Please select an article from the list..." : "Vyberte prosím článok zo zoznamu...",
"Move feed to folder" : "Presunúť kanál do priečinka",
"Move" : "Presunúť",
"User Name" : "Úžívateľské meno",
"Share" : "Zdieľať",
Expand All @@ -54,12 +55,14 @@
"Mark read" : "Označ ako prečítané",
"All articles" : "Všetky články",
"Starred" : "S hviezdičkou",
"Has feeds with errors!" : "Má kanály s chybami!",
"Explore" : "Preskúmať",
"Settings" : "Nastavenia",
"Keyboard shortcuts" : "Klávesové skratky",
"Disable mark read through scrolling" : "Vypnúť označovanie ako prečítané pri posune",
"Show all articles" : "Zobraziť všetky články",
"Reverse ordering (oldest on top)" : "Opačné zoradenie (od najstarších)",
"Disable automatic refresh" : "Zakázať automatické obnovenie",
"Are you sure you want to mark all read?" : "Ste si istý, že chcete označiť všetko ako prečítané?",
"Rename Folder" : "Premenovať Priečinok",
"Are you sure you want to delete?" : "Naozaj chcete vymazať?",
Expand Down Expand Up @@ -109,6 +112,7 @@
"Load next folder" : "Načítať ďalší priečinok",
"Scroll to active navigation entry" : "Posunte na aktiváciu položky menu",
"Shift" : "Shift",
"Mark current articles feed/folder as read" : "Označiť aktuálny kanál/priečinok s článkami ako prečítaný",
"All Articles" : "Všetky články",
"No feeds found to add" : "Žiadne kanály na pridanie neboli nájdené.",
"Subscribe to" : "Odobrať z",
Expand Down
1 change: 1 addition & 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
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
4 changes: 3 additions & 1 deletion lib/Controller/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
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 +47,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 +62,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
Loading

0 comments on commit f7a2959

Please sign in to comment.