]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix: return ocs data
authorChristopher Ng <chrng8@gmail.com>
Mon, 31 Jul 2023 19:10:50 +0000 (12:10 -0700)
committerChristopher Ng <chrng8@gmail.com>
Thu, 3 Aug 2023 22:30:11 +0000 (15:30 -0700)
Signed-off-by: Christopher Ng <chrng8@gmail.com>
apps/files_reminders/lib/Controller/ApiController.php

index 7f6e24debe25699fc448f0d5623d208dceab7618..af5cc1b32a76724f1518c7a0d814b3ae7639b88d 100644 (file)
@@ -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);
                }
        }
 }