]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix: create only if file exists
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
apps/files_reminders/lib/Service/ReminderService.php

index ddc34b16c6b20809eb55dc1658aea968afcd23ab..30465f6a69b9e5e51568b90aaa28daabad5705fc 100644 (file)
@@ -30,6 +30,7 @@ use DateTime;
 use DateTimeInterface;
 use DateTimeZone;
 use Exception;
+use OCA\FilesReminders\Exception\NodeNotFoundException;
 use OCA\FilesReminders\Service\ReminderService;
 use OCP\AppFramework\Db\DoesNotExistException;
 use OCP\AppFramework\Http;
@@ -95,6 +96,8 @@ class ApiController extends OCSController {
                try {
                        $this->reminderService->createOrUpdate($user, $fileId, $dueDate);
                        return new JSONResponse([], Http::STATUS_OK);
+               } catch (NodeNotFoundException $e) {
+                       return new JSONResponse([], Http::STATUS_NOT_FOUND);
                } catch (Throwable $th) {
                        $this->logger->error($th->getMessage(), ['exception' => $th]);
                        return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
index bf4cd5da14d784ca3554e79bf062d20e57391f74..fe746dc75ca0a205c2566507cc3c8a111b37330e 100644 (file)
@@ -31,6 +31,7 @@ use DateTimeZone;
 use OCA\FilesReminders\AppInfo\Application;
 use OCA\FilesReminders\Db\Reminder;
 use OCA\FilesReminders\Db\ReminderMapper;
+use OCA\FilesReminders\Exception\NodeNotFoundException;
 use OCA\FilesReminders\Exception\UserNotFoundException;
 use OCA\FilesReminders\Model\RichReminder;
 use OCP\AppFramework\Db\DoesNotExistException;
@@ -78,6 +79,9 @@ class ReminderService {
                );
        }
 
+       /**
+        * @throws NodeNotFoundException
+        */
        public function createOrUpdate(IUser $user, int $fileId, DateTime $dueDate): void {
                $now = new DateTime('now', new DateTimeZone('UTC'));
                try {
@@ -86,6 +90,10 @@ class ReminderService {
                        $reminder->setUpdatedAt($now);
                        $this->reminderMapper->update($reminder);
                } catch (DoesNotExistException $e) {
+                       $nodes = $this->root->getUserFolder($user->getUID())->getById($fileId);
+                       if (empty($nodes)) {
+                               throw new NodeNotFoundException();
+                       }
                        // Create new reminder if no reminder is found
                        $reminder = new Reminder();
                        $reminder->setUserId($user->getUID());