Move to OCS routes for new comments api

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-03-06 16:10:07 +01:00
parent 7ab2a839e7
commit fb06cac246
4 changed files with 19 additions and 9 deletions

View File

@@ -23,14 +23,17 @@
namespace OCA\Deck\Controller;
use OCA\Deck\BadRequestException;
use OCA\Deck\Service\CommentService;
use OCA\Deck\StatusException;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
class CommentsApiController extends ApiController {
class CommentsApiController extends OCSController {
/** @var CommentService */
private $commentService;
@@ -45,7 +48,6 @@ class CommentsApiController extends ApiController {
/**
* @NoAdminRequired
* @NoCSRFRequired
* @throws StatusException
*/
public function list(string $cardId, int $limit = 20, int $offset = 0): DataResponse {
@@ -54,7 +56,6 @@ class CommentsApiController extends ApiController {
/**
* @NoAdminRequired
* @NoCSRFRequired
* @throws StatusException
*/
public function create(string $cardId, string $message, string $parentId = '0'): DataResponse {
@@ -63,7 +64,6 @@ class CommentsApiController extends ApiController {
/**
* @NoAdminRequired
* @NoCSRFRequired
* @throws StatusException
*/
public function update(string $cardId, string $commentId, string $message): DataResponse {
@@ -72,7 +72,6 @@ class CommentsApiController extends ApiController {
/**
* @NoAdminRequired
* @NoCSRFRequired
* @throws StatusException
*/
public function delete(string $cardId, string $commentId): DataResponse {

View File

@@ -28,6 +28,8 @@ use OCA\Deck\StatusException;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Middleware;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCSController;
use OCP\ILogger;
use OCP\Util;
use OCP\IConfig;
@@ -65,6 +67,11 @@ class ExceptionMiddleware extends Middleware {
if ($this->config->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
$this->logger->logException($exception);
}
if ($controller instanceof OCSController) {
$exception = new OCSException($exception->getMessage(), $exception->getStatus(), $exception);
throw $exception;
}
return new JSONResponse([
'status' => $exception->getStatus(),
'message' => $exception->getMessage()

View File

@@ -151,6 +151,7 @@ class CommentService {
'actorId' => $comment->getActorId(),
'actorType' => $comment->getActorType(),
'actorDisplayName' => $actorDisplayName,
'creationDateTime' => $comment->getCreationDateTime()->format(\DateTime::ATOM),
'mentions' => array_map(function($mention) {
try {
$displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']);