aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_reminders/lib/Controller/ApiController.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_reminders/lib/Controller/ApiController.php')
-rw-r--r--apps/files_reminders/lib/Controller/ApiController.php52
1 files changed, 17 insertions, 35 deletions
diff --git a/apps/files_reminders/lib/Controller/ApiController.php b/apps/files_reminders/lib/Controller/ApiController.php
index 91b7e51eb6f..c95a74a04f4 100644
--- a/apps/files_reminders/lib/Controller/ApiController.php
+++ b/apps/files_reminders/lib/Controller/ApiController.php
@@ -3,25 +3,8 @@
declare(strict_types=1);
/**
- * @copyright 2023 Christopher Ng <chrng8@gmail.com>
- *
- * @author Christopher Ng <chrng8@gmail.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\FilesReminders\Controller;
@@ -31,8 +14,8 @@ use DateTimeInterface;
use DateTimeZone;
use Exception;
use OCA\FilesReminders\Exception\NodeNotFoundException;
+use OCA\FilesReminders\Exception\ReminderNotFoundException;
use OCA\FilesReminders\Service\ReminderService;
-use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
@@ -56,10 +39,10 @@ class ApiController extends OCSController {
* Get a reminder
*
* @param int $fileId ID of the file
- * @return DataResponse<Http::STATUS_OK, array{dueDate: ?string}, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, array<empty>, array{}>
+ * @return DataResponse<Http::STATUS_OK, array{dueDate: ?string}, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, list<empty>, array{}>
*
* 200: Reminder returned
- * 401: User not found
+ * 401: Account not found
*/
#[NoAdminRequired]
public function get(int $fileId): DataResponse {
@@ -70,15 +53,14 @@ class ApiController extends OCSController {
try {
$reminder = $this->reminderService->getDueForUser($user, $fileId);
- $reminderData = [
+ if ($reminder === null) {
+ return new DataResponse(['dueDate' => null], Http::STATUS_OK);
+ }
+ return new DataResponse([
'dueDate' => $reminder->getDueDate()->format(DateTimeInterface::ATOM), // ISO 8601
- ];
- return new DataResponse($reminderData, Http::STATUS_OK);
- } catch (DoesNotExistException $e) {
- $reminderData = [
- 'dueDate' => null,
- ];
- return new DataResponse($reminderData, Http::STATUS_OK);
+ ], Http::STATUS_OK);
+ } catch (NodeNotFoundException $e) {
+ return new DataResponse(['dueDate' => null], Http::STATUS_OK);
}
}
@@ -88,12 +70,12 @@ class ApiController extends OCSController {
* @param int $fileId ID of the file
* @param string $dueDate ISO 8601 formatted date time string
*
- * @return DataResponse<Http::STATUS_OK|Http::STATUS_CREATED|Http::STATUS_BAD_REQUEST|Http::STATUS_UNAUTHORIZED|Http::STATUS_NOT_FOUND, array<empty>, array{}>
+ * @return DataResponse<Http::STATUS_OK|Http::STATUS_CREATED|Http::STATUS_BAD_REQUEST|Http::STATUS_UNAUTHORIZED|Http::STATUS_NOT_FOUND, list<empty>, array{}>
*
* 200: Reminder updated
* 201: Reminder created successfully
* 400: Creating reminder is not possible
- * 401: User not found
+ * 401: Account not found
* 404: File not found
*/
#[NoAdminRequired]
@@ -126,10 +108,10 @@ class ApiController extends OCSController {
*
* @param int $fileId ID of the file
*
- * @return DataResponse<Http::STATUS_OK|Http::STATUS_UNAUTHORIZED|Http::STATUS_NOT_FOUND, array<empty>, array{}>
+ * @return DataResponse<Http::STATUS_OK|Http::STATUS_UNAUTHORIZED|Http::STATUS_NOT_FOUND, list<empty>, array{}>
*
* 200: Reminder deleted successfully
- * 401: User not found
+ * 401: Account not found
* 404: Reminder not found
*/
#[NoAdminRequired]
@@ -142,7 +124,7 @@ class ApiController extends OCSController {
try {
$this->reminderService->remove($user, $fileId);
return new DataResponse([], Http::STATUS_OK);
- } catch (DoesNotExistException $e) {
+ } catch (NodeNotFoundException|ReminderNotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
}