]> source.dussan.org Git - nextcloud-server.git/commitdiff
feat(files_reminders): add remove endpoint
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/appinfo/routes.php
apps/files_reminders/lib/Controller/ApiController.php
apps/files_reminders/lib/Service/ReminderService.php

index e912efe0284a1d76078cb36852887db64ab833e6..8dfd785669ba1d639ef6f1c4d8996acc9ee9b333 100644 (file)
@@ -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],
        ],
 ];
index de69997f61669db3f13f5275f26436be04d17239..ddc34b16c6b20809eb55dc1658aea968afcd23ab 100644 (file)
@@ -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);
+               }
+       }
 }
index 0142802f3f163191fc18addce21fb37756fbb437..bf4cd5da14d784ca3554e79bf062d20e57391f74 100644 (file)
@@ -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