From bdf07413d02a23aa460aa821191325b04561d597 Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Mon, 31 Jul 2023 12:10:50 -0700 Subject: [PATCH] enh: return created status code Signed-off-by: Christopher Ng --- apps/files_reminders/lib/Controller/ApiController.php | 5 ++++- apps/files_reminders/lib/Service/ReminderService.php | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/files_reminders/lib/Controller/ApiController.php b/apps/files_reminders/lib/Controller/ApiController.php index 30465f6a69b..fc1b647148d 100644 --- a/apps/files_reminders/lib/Controller/ApiController.php +++ b/apps/files_reminders/lib/Controller/ApiController.php @@ -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); diff --git a/apps/files_reminders/lib/Service/ReminderService.php b/apps/files_reminders/lib/Service/ReminderService.php index fe746dc75ca..8dbec6d5df7 100644 --- a/apps/files_reminders/lib/Service/ReminderService.php +++ b/apps/files_reminders/lib/Service/ReminderService.php @@ -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; } } -- 2.39.5