]> source.dussan.org Git - nextcloud-server.git/commitdiff
enh: return created status code
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 30465f6a69b9e5e51568b90aaa28daabad5705fc..fc1b647148daf7e517b4d468358188c0f59425f0 100644 (file)
@@ -94,7 +94,10 @@ class ApiController extends OCSController {
                }
 
                try {
-                       $this->reminderService->createOrUpdate($user, $fileId, $dueDate);
+                       $created = $this->reminderService->createOrUpdate($user, $fileId, $dueDate);
+                       if ($created) {
+                               return new JSONResponse([], Http::STATUS_CREATED);
+                       }
                        return new JSONResponse([], Http::STATUS_OK);
                } catch (NodeNotFoundException $e) {
                        return new JSONResponse([], Http::STATUS_NOT_FOUND);
index fe746dc75ca0a205c2566507cc3c8a111b37330e..8dbec6d5df70c61d2de2f20e594c53c9d6d22262 100644 (file)
@@ -80,15 +80,18 @@ class ReminderService {
        }
 
        /**
+        * @return bool true if created, false if updated
+        *
         * @throws NodeNotFoundException
         */
-       public function createOrUpdate(IUser $user, int $fileId, DateTime $dueDate): void {
+       public function createOrUpdate(IUser $user, int $fileId, DateTime $dueDate): bool {
                $now = new DateTime('now', new DateTimeZone('UTC'));
                try {
                        $reminder = $this->reminderMapper->findDueForUser($user, $fileId);
                        $reminder->setDueDate($dueDate);
                        $reminder->setUpdatedAt($now);
                        $this->reminderMapper->update($reminder);
+                       return false;
                } catch (DoesNotExistException $e) {
                        $nodes = $this->root->getUserFolder($user->getUID())->getById($fileId);
                        if (empty($nodes)) {
@@ -102,6 +105,7 @@ class ReminderService {
                        $reminder->setUpdatedAt($now);
                        $reminder->setCreatedAt($now);
                        $this->reminderMapper->insert($reminder);
+                       return true;
                }
        }