mirror of
https://github.com/nextcloud/server.git
synced 2026-02-23 01:40:59 -05:00
feat(files_reminders): add remove endpoint
Signed-off-by: Christopher Ng <chrng8@gmail.com>
(cherry picked from commit 777a791e72)
This commit is contained in:
parent
fb71f8cec5
commit
ab357bfe20
3 changed files with 30 additions and 5 deletions
|
|
@ -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],
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue