Skip to content

Commit 43898a7

Browse files
committed
chore: migrate some routes to the new format
Signed-off-by: Sean Molenaar <[email protected]>
1 parent bb29359 commit 43898a7

10 files changed

+38
-40
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ You can also check [on GitHub](https://github.com/nextcloud/news/releases), the
77
# Unreleased
88
## [25.x.x]
99
### Changed
10+
- Migrate routes to new location in the controllers
1011

1112
### Fixed
1213

appinfo/routes.php

-38
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,14 @@
1515

1616
return ['routes' => [
1717
// page
18-
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
19-
['name' => 'page#settings', 'url' => '/settings', 'verb' => 'GET'],
20-
['name' => 'page#update_settings', 'url' => '/settings', 'verb' => 'PUT'],
2118
['name' => 'page#manifest', 'url' => '/manifest.webapp', 'verb' => 'GET'],
22-
['name' => 'page#explore', 'url' => '/explore/feeds.{lang}.json', 'verb' => 'GET'],
2319

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

28-
// folders
29-
['name' => 'folder#index', 'url' => '/folders', 'verb' => 'GET'],
30-
['name' => 'folder#create', 'url' => '/folders', 'verb' => 'POST'],
31-
['name' => 'folder#delete', 'url' => '/folders/{folderId}', 'verb' => 'DELETE'],
32-
['name' => 'folder#restore', 'url' => '/folders/{folderId}/restore', 'verb' => 'POST'],
33-
['name' => 'folder#rename', 'url' => '/folders/{folderId}/rename', 'verb' => 'POST'],
34-
['name' => 'folder#read', 'url' => '/folders/{folderId}/read', 'verb' => 'POST'],
35-
['name' => 'folder#open', 'url' => '/folders/{folderId}/open', 'verb' => 'POST'],
36-
37-
// feeds
38-
['name' => 'feed#index', 'url' => '/feeds', 'verb' => 'GET'],
39-
['name' => 'feed#create', 'url' => '/feeds', 'verb' => 'POST'],
40-
['name' => 'feed#delete', 'url' => '/feeds/{feedId}', 'verb' => 'DELETE'],
41-
['name' => 'feed#restore', 'url' => '/feeds/{feedId}/restore', 'verb' => 'POST'],
42-
['name' => 'feed#read', 'url' => '/feeds/{feedId}/read', 'verb' => 'POST'],
43-
['name' => 'feed#update', 'url' => '/feeds/{feedId}/update', 'verb' => 'POST'],
44-
['name' => 'feed#active', 'url' => '/feeds/active', 'verb' => 'GET'],
45-
['name' => 'feed#import', 'url' => '/feeds/import/articles', 'verb' => 'POST'],
46-
['name' => 'feed#patch', 'url' => '/feeds/{feedId}', 'verb' => 'PATCH'],
47-
48-
// items
49-
['name' => 'item#index', 'url' => '/items', 'verb' => 'GET'],
50-
['name' => 'item#new_items', 'url' => '/items/new', 'verb' => 'GET'],
51-
['name' => 'item#readAll', 'url' => '/items/read', 'verb' => 'POST'],
52-
['name' => 'item#read', 'url' => '/items/{itemId}/read', 'verb' => 'POST'],
53-
['name' => 'item#read_multiple', 'url' => '/items/read/multiple', 'verb' => 'POST'],
54-
['name' => 'item#star', 'url' => '/items/{feedId}/{guidHash}/star', 'verb' => 'POST'],
55-
['name' => 'item#share', 'url' => '/items/{itemId}/share/{shareRecipientId}', 'verb' => 'POST'],
56-
57-
// export
58-
['name' => 'export#opml', 'url' => '/export/opml', 'verb' => 'GET'],
59-
['name' => 'export#articles', 'url' => '/export/articles', 'verb' => 'GET'],
60-
6124
// general API
6225
['name' => 'api#index', 'url' => '/api', 'verb' => 'GET'],
63-
6426
['name' => 'utility_api#preflighted_cors', 'url' => '/api/{apiVersion}/{path}', 'verb' => 'OPTIONS', 'requirements' => ['apiVersion' => 'v(1-[23]|2)', 'path' => '.+']],
6527
['name' => 'utility_api#version', 'url' => '/api/{apiVersion}/version', 'verb' => 'GET', 'requirements' => ['apiVersion' => 'v(1-[23]|2)']],
6628

lib/Controller/ApiController.php

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use OCP\AppFramework\Http\Attribute\CORS;
2727
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
2828
use OCP\AppFramework\Http\Attribute\PublicPage;
29+
use OCP\AppFramework\Http\Attribute\ApiRoute;
2930

3031
/**
3132
* Class ApiController

lib/Controller/Controller.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected function getUser(): ?IUser
5656
/**
5757
* @return string
5858
*/
59-
protected function getUserId()
59+
protected function getUserId(): string
6060
{
6161
return $this->getUser()->getUID();
6262
}

lib/Controller/ExportController.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use OCP\IUserSession;
2424
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
2525
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
26-
use OCP\AppFramework\Http\Attribute\CORS;
26+
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
2727

2828
/**
2929
* Class ExportController
@@ -47,6 +47,7 @@ public function __construct(
4747

4848
#[NoCSRFRequired]
4949
#[NoAdminRequired]
50+
#[FrontpageRoute(verb: 'GET', url: '/export/opml')]
5051
public function opml(): DataDownloadResponse
5152
{
5253
$date = date('Y-m-d');
@@ -61,6 +62,7 @@ public function opml(): DataDownloadResponse
6162

6263
#[NoCSRFRequired]
6364
#[NoAdminRequired]
65+
#[FrontpageRoute(verb: 'GET', url: '/export/articles')]
6466
public function articles(): JSONResponse
6567
{
6668
$feeds = $this->feedService->findAllForUser($this->getUserId());

lib/Controller/FeedController.php

+10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use OCP\IConfig;
2525
use OCP\AppFramework\Http;
2626
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
27+
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
2728

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

4748

4849
#[NoAdminRequired]
50+
#[FrontpageRoute(verb: 'GET', url: '/feeds')]
4951
public function index(): array
5052
{
5153

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

7375

7476
#[NoAdminRequired]
77+
#[FrontpageRoute(verb: 'GET', url: '/feeds/active')]
7578
public function active(): array
7679
{
7780
$feedId = (int) $this->settings->getUserValue(
@@ -126,6 +129,7 @@ public function active(): array
126129
* @return array|JSONResponse
127130
*/
128131
#[NoAdminRequired]
132+
#[FrontpageRoute(verb: 'POST', url: '/feeds')]
129133
public function create(
130134
string $url,
131135
?int $parentFolderId,
@@ -180,6 +184,7 @@ public function create(
180184
* @return array|JSONResponse
181185
*/
182186
#[NoAdminRequired]
187+
#[FrontpageRoute(verb: 'DELETE', url: '/feeds/{feedId}')]
183188
public function delete(int $feedId)
184189
{
185190
try {
@@ -200,6 +205,7 @@ public function delete(int $feedId)
200205
* @return array|JSONResponse
201206
*/
202207
#[NoAdminRequired]
208+
#[FrontpageRoute(verb: 'POST', url: '/feeds/{feedId}/update')]
203209
public function update(int $feedId)
204210
{
205211
try {
@@ -227,6 +233,7 @@ public function update(int $feedId)
227233
* @return array
228234
*/
229235
#[NoAdminRequired]
236+
#[FrontpageRoute(verb: 'POST', url: '/feeds/import/articles')]
230237
public function import(array $json): array
231238
{
232239
$feed = $this->importService->importArticles($this->getUserId(), $json);
@@ -249,6 +256,7 @@ public function import(array $json): array
249256
* @return array
250257
*/
251258
#[NoAdminRequired]
259+
#[FrontpageRoute(verb: 'POST', url: '/feeds/{feedId}/read')]
252260
public function read(int $feedId, int $highestItemId): array
253261
{
254262
$this->feedService->read($this->getUserId(), $feedId, $highestItemId);
@@ -270,6 +278,7 @@ public function read(int $feedId, int $highestItemId): array
270278
* @return array|JSONResponse
271279
*/
272280
#[NoAdminRequired]
281+
#[FrontpageRoute(verb: 'POST', url: '/feeds/{feedId}/restore')]
273282
public function restore(int $feedId)
274283
{
275284
try {
@@ -295,6 +304,7 @@ public function restore(int $feedId)
295304
* @return array|JSONResponse
296305
*/
297306
#[NoAdminRequired]
307+
#[FrontpageRoute(verb: 'PATCH', url: '/feeds/{feedId}')]
298308
public function patch(
299309
int $feedId,
300310
?bool $pinned = null,

lib/Controller/FolderController.php

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use \OCP\IRequest;
1919
use \OCP\AppFramework\Http;
2020
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
21+
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
2122

2223
use \OCA\News\Service\FolderServiceV2;
2324
use \OCA\News\Service\Exceptions\ServiceNotFoundException;
@@ -43,6 +44,7 @@ public function __construct(
4344
* @psalm-return array{folders: array}
4445
*/
4546
#[NoAdminRequired]
47+
#[FrontpageRoute(verb: 'GET', url: '/folders')]
4648
public function index(): array
4749
{
4850
$folders = $this->folderService->findAllForUser($this->getUserId());
@@ -57,6 +59,7 @@ public function index(): array
5759
* @return array|JSONResponse
5860
*/
5961
#[NoAdminRequired]
62+
#[FrontpageRoute(verb: 'POST', url: '/folders/{folderId}/open')]
6063
public function open(?int $folderId, bool $open)
6164
{
6265
$folderId = $folderId === 0 ? null : $folderId;
@@ -78,6 +81,7 @@ public function open(?int $folderId, bool $open)
7881
* @return array|JSONResponse
7982
*/
8083
#[NoAdminRequired]
84+
#[FrontpageRoute(verb: 'POST', url: '/folders')]
8185
public function create(string $folderName, ?int $parent = null)
8286
{
8387
$this->folderService->purgeDeleted($this->getUserId(), time() - 600);
@@ -93,6 +97,7 @@ public function create(string $folderName, ?int $parent = null)
9397
* @return array|JSONResponse
9498
*/
9599
#[NoAdminRequired]
100+
#[FrontpageRoute(verb: 'DELETE', url: '/folders/{folderId}')]
96101
public function delete(?int $folderId)
97102
{
98103
if (is_null($folderId)) {
@@ -117,6 +122,7 @@ public function delete(?int $folderId)
117122
* @return array|JSONResponse
118123
*/
119124
#[NoAdminRequired]
125+
#[FrontpageRoute(verb: 'POST', url: '/folders/{folderId}/rename')]
120126
public function rename(?int $folderId, string $folderName)
121127
{
122128
if (is_null($folderId)) {
@@ -143,6 +149,7 @@ public function rename(?int $folderId, string $folderName)
143149
* @throws ServiceNotFoundException
144150
*/
145151
#[NoAdminRequired]
152+
#[FrontpageRoute(verb: 'POST', url: '/folders/{folderId}/read')]
146153
public function read(?int $folderId, int $maxItemId): void
147154
{
148155
$folderId = $folderId === 0 ? null : $folderId;
@@ -157,6 +164,7 @@ public function read(?int $folderId, int $maxItemId): void
157164
* @return array|JSONResponse
158165
*/
159166
#[NoAdminRequired]
167+
#[FrontpageRoute(verb: 'POST', url: '/folders/{folderId}/restore')]
160168
public function restore(?int $folderId)
161169
{
162170
$folderId = $folderId === 0 ? null : $folderId;

lib/Controller/ItemController.php

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use \OCP\IConfig;
2222
use \OCP\AppFramework\Http;
2323
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
24+
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
2425

2526
use \OCA\News\Service\Exceptions\ServiceException;
2627
use \OCA\News\Service\Exceptions\ServiceNotFoundException;
@@ -64,6 +65,7 @@ public function __construct(
6465
* @return array
6566
*/
6667
#[NoAdminRequired]
68+
#[FrontpageRoute(verb: 'GET', url: '/items')]
6769
public function index(
6870
int $type = 3,
6971
int $id = 0,
@@ -184,6 +186,7 @@ public function index(
184186
* @return array
185187
*/
186188
#[NoAdminRequired]
189+
#[FrontpageRoute(verb: 'GET', url: '/items/new')]
187190
public function newItems(int $type, int $id, $lastModified = 0): array
188191
{
189192
$showAll = $this->settings->getUserValue(
@@ -245,6 +248,7 @@ public function newItems(int $type, int $id, $lastModified = 0): array
245248
* @return array|JSONResponse
246249
*/
247250
#[NoAdminRequired]
251+
#[FrontpageRoute(verb: 'POST', url: '/items/{feedId}/{guidHash}/star')]
248252
public function star(int $feedId, string $guidHash, bool $isStarred)
249253
{
250254
try {
@@ -269,6 +273,7 @@ public function star(int $feedId, string $guidHash, bool $isStarred)
269273
* @return array|JSONResponse
270274
*/
271275
#[NoAdminRequired]
276+
#[FrontpageRoute(verb: 'POST', url: '/items/{itemId}/read')]
272277
public function read(int $itemId, $isRead = true)
273278
{
274279
try {
@@ -287,6 +292,7 @@ public function read(int $itemId, $isRead = true)
287292
* @return array
288293
*/
289294
#[NoAdminRequired]
295+
#[FrontpageRoute(verb: 'POST', url: '/items/read')]
290296
public function readAll(int $highestItemId): array
291297
{
292298
$this->itemService->readAll($this->getUserId(), $highestItemId);
@@ -300,6 +306,7 @@ public function readAll(int $highestItemId): array
300306
* @return void
301307
*/
302308
#[NoAdminRequired]
309+
#[FrontpageRoute(verb: 'POST', url: '/items/read/multiple')]
303310
public function readMultiple(array $itemIds): void
304311
{
305312
foreach ($itemIds as $id) {
@@ -317,6 +324,7 @@ public function readMultiple(array $itemIds): void
317324
* @param string $shareRecipientId User to share the item with
318325
*/
319326
#[NoAdminRequired]
327+
#[FrontpageRoute(verb: 'POST', url: '/items/{itemId}/share/{shareRecipientId}')]
320328
public function share(int $itemId, string $shareRecipientId)
321329
{
322330
try {

lib/Controller/PageController.php

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use OCP\AppFramework\Services\IInitialState;
2828
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
2929
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
30+
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
3031

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

5455
#[NoCSRFRequired]
5556
#[NoAdminRequired]
57+
#[FrontpageRoute(verb: 'GET', url: '/')]
5658
public function index(): TemplateResponse
5759
{
5860
$status = $this->statusService->getStatus();
@@ -110,6 +112,7 @@ public function index(): TemplateResponse
110112
}
111113

112114
#[NoAdminRequired]
115+
#[FrontpageRoute(verb: 'GET', url: '/settings')]
113116
public function settings(): array
114117
{
115118
$settings = [
@@ -159,6 +162,7 @@ public function settings(): array
159162
* @param bool $disableRefresh
160163
*/
161164
#[NoAdminRequired]
165+
#[FrontpageRoute(verb: 'PUT', url: '/settings')]
162166
public function updateSettings(
163167
bool $showAll,
164168
bool $compact,
@@ -193,6 +197,7 @@ public function updateSettings(
193197
* @return Http\JSONResponse|array
194198
*/
195199
#[NoAdminRequired]
200+
#[FrontpageRoute(verb: 'GET', url: '/explore/feeds.{lang}.json')]
196201
public function explore(string $lang)
197202
{
198203
$this->config->setUserValue(

lib/Controller/UtilityApiController.php

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
2323
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
2424
use OCP\AppFramework\Http\Attribute\CORS;
25+
use OCP\AppFramework\Http\Attribute\ApiRoute;
2526

2627
use \OCA\News\Service\StatusService;
2728

0 commit comments

Comments
 (0)