From 3ade06cd9c1ddcf8a5d0a140d40b7fab0ecfccd3 Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Mon, 31 Jul 2023 12:10:50 -0700 Subject: [PATCH] fix: return ocs data Signed-off-by: Christopher Ng --- .../lib/Controller/ApiController.php | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/apps/files_reminders/lib/Controller/ApiController.php b/apps/files_reminders/lib/Controller/ApiController.php index 7f6e24debe2..af5cc1b32a7 100644 --- a/apps/files_reminders/lib/Controller/ApiController.php +++ b/apps/files_reminders/lib/Controller/ApiController.php @@ -34,7 +34,7 @@ use OCA\FilesReminders\Exception\NodeNotFoundException; use OCA\FilesReminders\Service\ReminderService; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Http; -use OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCSController; use OCP\IRequest; use OCP\IUserSession; @@ -55,10 +55,10 @@ class ApiController extends OCSController { /** * Get a reminder */ - public function get(int $fileId): JSONResponse { + public function get(int $fileId): DataResponse { $user = $this->userSession->getUser(); if ($user === null) { - return new JSONResponse([], Http::STATUS_UNAUTHORIZED); + return new DataResponse([], Http::STATUS_UNAUTHORIZED); } try { @@ -66,15 +66,15 @@ class ApiController extends OCSController { $reminderData = [ 'dueDate' => $reminder->getDueDate()->format(DateTimeInterface::ATOM), // ISO 8601 ]; - return new JSONResponse($reminderData, Http::STATUS_OK); + return new DataResponse($reminderData, Http::STATUS_OK); } catch (DoesNotExistException $e) { $reminderData = [ 'dueDate' => null, ]; - return new JSONResponse($reminderData, Http::STATUS_OK); + return new DataResponse($reminderData, Http::STATUS_OK); } catch (Throwable $th) { $this->logger->error($th->getMessage(), ['exception' => $th]); - return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); + return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); } } @@ -83,50 +83,50 @@ class ApiController extends OCSController { * * @param string $dueDate ISO 8601 formatted date time string */ - public function set(int $fileId, string $dueDate): JSONResponse { + public function set(int $fileId, string $dueDate): DataResponse { try { $dueDate = (new DateTime($dueDate))->setTimezone(new DateTimeZone('UTC')); } catch (Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); - return new JSONResponse([], Http::STATUS_BAD_REQUEST); + return new DataResponse([], Http::STATUS_BAD_REQUEST); } $user = $this->userSession->getUser(); if ($user === null) { - return new JSONResponse([], Http::STATUS_UNAUTHORIZED); + return new DataResponse([], Http::STATUS_UNAUTHORIZED); } try { $created = $this->reminderService->createOrUpdate($user, $fileId, $dueDate); if ($created) { - return new JSONResponse([], Http::STATUS_CREATED); + return new DataResponse([], Http::STATUS_CREATED); } - return new JSONResponse([], Http::STATUS_OK); + return new DataResponse([], Http::STATUS_OK); } catch (NodeNotFoundException $e) { - return new JSONResponse([], Http::STATUS_NOT_FOUND); + return new DataResponse([], Http::STATUS_NOT_FOUND); } catch (Throwable $th) { $this->logger->error($th->getMessage(), ['exception' => $th]); - return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); + return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); } } /** * Remove a reminder */ - public function remove(int $fileId): JSONResponse { + public function remove(int $fileId): DataResponse { $user = $this->userSession->getUser(); if ($user === null) { - return new JSONResponse([], Http::STATUS_UNAUTHORIZED); + return new DataResponse([], Http::STATUS_UNAUTHORIZED); } try { $this->reminderService->remove($user, $fileId); - return new JSONResponse([], Http::STATUS_OK); + return new DataResponse([], Http::STATUS_OK); } catch (DoesNotExistException $e) { - return new JSONResponse([], Http::STATUS_NOT_FOUND); + return new DataResponse([], Http::STATUS_NOT_FOUND); } catch (Throwable $th) { $this->logger->error($th->getMessage(), ['exception' => $th]); - return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); + return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); } } } -- 2.39.5