}
try {
- $this->reminderService->createOrUpdate($user, $fileId, $dueDate);
+ $created = $this->reminderService->createOrUpdate($user, $fileId, $dueDate);
+ if ($created) {
+ return new JSONResponse([], Http::STATUS_CREATED);
+ }
return new JSONResponse([], Http::STATUS_OK);
} catch (NodeNotFoundException $e) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
}
/**
+ * @return bool true if created, false if updated
+ *
* @throws NodeNotFoundException
*/
- public function createOrUpdate(IUser $user, int $fileId, DateTime $dueDate): void {
+ public function createOrUpdate(IUser $user, int $fileId, DateTime $dueDate): bool {
$now = new DateTime('now', new DateTimeZone('UTC'));
try {
$reminder = $this->reminderMapper->findDueForUser($user, $fileId);
$reminder->setDueDate($dueDate);
$reminder->setUpdatedAt($now);
$this->reminderMapper->update($reminder);
+ return false;
} catch (DoesNotExistException $e) {
$nodes = $this->root->getUserFolder($user->getUID())->getById($fileId);
if (empty($nodes)) {
$reminder->setUpdatedAt($now);
$reminder->setCreatedAt($now);
$this->reminderMapper->insert($reminder);
+ return true;
}
}