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

v2 API (feeds) #1338

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
['name' => 'folder_api_v2#update', 'url' => '/api/v2/folders/{folderId}', 'verb' => 'PATCH'],
['name' => 'folder_api_v2#delete', 'url' => '/api/v2/folders/{folderId}', 'verb' => 'DELETE'],

['name' => 'feed_api_v2#create', 'url' => '/api/v2/feeds', 'verb' => 'POST'],
['name' => 'feed_api_v2#update', 'url' => '/api/v2/feeds/{feedId}', 'verb' => 'PATCH'],
['name' => 'feed_api_v2#delete', 'url' => '/api/v2/feeds/{feedId}', 'verb' => 'DELETE'],

// 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
108 changes: 108 additions & 0 deletions lib/Controller/FeedApiV2Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php
/**
* Nextcloud - News
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Paul Tirk <paultirk@paultirk.com>
* @copyright 2020 Paul Tirk
*/

namespace OCA\News\Controller;

use OCA\News\Db\Feed;
use \Psr\Log\LoggerInterface;

use \OCP\IRequest;
use \OCP\IUserSession;
use \OCP\AppFramework\Http;

use \OCA\News\Service\FeedServiceV2;
use \OCA\News\Service\ItemServiceV2;
use \OCA\News\Service\Exceptions\ServiceNotFoundException;
use \OCA\News\Service\Exceptions\ServiceConflictException;

class FeedApiV2Controller extends ApiController
{
use ApiPayloadTrait;
use JSONHttpErrorTrait;

private $itemService;
private $feedService;
private $loggerInterface;

public function __construct(
IRequest $request,
IUserSession $userSession,
FeedServiceV2 $feedService,
ItemServiceV2 $itemService,
LoggerInterface $loggerInterface
) {
parent::__construct($request, $userSession);
$this->feedService = $feedService;
$this->itemService = $itemService;

$this->loggerInterface = $loggerInterface;
}

/**
* @NoAdminRequired
* @NoCSRFRequired
* @CORS
*
* @param string $url
* @param string $name
* @param int $ordering
* @param int $folderId
* @param bool $isPinned
* @param bool $fullTextEnabled
* @param string $basicAuthUser
* @param string $basicAuthPassword
* @return array|mixed|\OCP\AppFramework\Http\JSONResponse
*/
public function create(
string $url,
string $name = '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be like this

Suggested change
string $name = '',
?string $name = null,

int $ordering = 0,
int $folderId = null,
bool $isPinned = false,
bool $fullTextEnabled = false,
string $basicAuthUser = null,
string $basicAuthPassword = null
Comment on lines +71 to +72
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will fail with the default because null is not a string

Suggested change
string $basicAuthUser = null,
string $basicAuthPassword = null
?string $basicAuthUser = null,
?string $basicAuthPassword = null

) {
}

/**
* @NoCSRFRequired
*
* @param Entity $userId
* @param int $feedId
*/
public function update(
int $feedId,
string $url = '',
string $name = '',
int $ordering = 0,
int $folderId = null,
bool $isPinned = false,
bool $fullTextEnabled = false,
string $basicAuthUser = null,
string $basicAuthPassword = null
) {
}

/**
* @NoAdminRequired
* @NoCSRFRequired
* @CORS
*
* @param int $feedId
* @return array|\OCP\AppFramework\Http\JSONResponse
*/
public function delete(int $feedId)
{
}

}