feat(files_reminders): add remove endpoint

Signed-off-by: Christopher Ng <chrng8@gmail.com>
(cherry picked from commit 777a791e72)
This commit is contained in:
Christopher Ng 2023-07-31 12:10:50 -07:00
parent fb71f8cec5
commit ab357bfe20
3 changed files with 30 additions and 5 deletions

View 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],
],
];

View 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);
}
}
}

View 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