From: Christopher Ng Date: Mon, 31 Jul 2023 19:10:50 +0000 (-0700) Subject: feat(files_reminders): add remove endpoint X-Git-Tag: v28.0.0beta1~601^2~20 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=777a791e72b9e8982228ff5a39cd61b7f051d8e4;p=nextcloud-server.git feat(files_reminders): add remove endpoint Signed-off-by: Christopher Ng --- diff --git a/apps/files_reminders/appinfo/routes.php b/apps/files_reminders/appinfo/routes.php index e912efe0284..8dfd785669b 100644 --- a/apps/files_reminders/appinfo/routes.php +++ b/apps/files_reminders/appinfo/routes.php @@ -32,5 +32,6 @@ return [ 'ocs' => [ ['name' => 'Api#get', 'url' => '/api/v{version}/get/{fileId}', 'verb' => 'GET', 'requirements' => $requirements], ['name' => 'Api#set', 'url' => '/api/v{version}/set/{fileId}', 'verb' => 'PUT', 'requirements' => $requirements], + ['name' => 'Api#remove', 'url' => '/api/v{version}/remove/{fileId}', 'verb' => 'DELETE', 'requirements' => $requirements], ], ]; diff --git a/apps/files_reminders/lib/Controller/ApiController.php b/apps/files_reminders/lib/Controller/ApiController.php index de69997f616..ddc34b16c6b 100644 --- a/apps/files_reminders/lib/Controller/ApiController.php +++ b/apps/files_reminders/lib/Controller/ApiController.php @@ -67,11 +67,7 @@ class ApiController extends OCSController { ]; return new JSONResponse($reminderData, Http::STATUS_OK); } catch (DoesNotExistException $e) { - // Return null when no reminder is found - $reminderData = [ - 'dueDate' => null, - ]; - return new JSONResponse($reminderData, Http::STATUS_OK); + 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); @@ -104,4 +100,24 @@ class ApiController extends OCSController { return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); } } + + /** + * Remove a reminder + */ + public function remove(int $fileId): JSONResponse { + $user = $this->userSession->getUser(); + if ($user === null) { + return new JSONResponse([], Http::STATUS_UNAUTHORIZED); + } + + try { + $this->reminderService->remove($user, $fileId); + return new JSONResponse([], Http::STATUS_OK); + } catch (DoesNotExistException $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); + } + } } diff --git a/apps/files_reminders/lib/Service/ReminderService.php b/apps/files_reminders/lib/Service/ReminderService.php index 0142802f3f1..bf4cd5da14d 100644 --- a/apps/files_reminders/lib/Service/ReminderService.php +++ b/apps/files_reminders/lib/Service/ReminderService.php @@ -97,6 +97,14 @@ class ReminderService { } } + /** + * @throws DoesNotExistException + */ + public function remove(IUser $user, int $fileId): void { + $reminder = $this->reminderMapper->findDueForUser($user, $fileId); + $this->reminderMapper->delete($reminder); + } + /** * @throws DoesNotExistException * @throws UserNotFoundException