Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api-create with param for favorite #284

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions controller/notesapicontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ public function get($id, $exclude='') {
* @NoCSRFRequired
*
* @param string $content
* @param boolean $favorite
* @return DataResponse
*/
public function create($content) {
return $this->respond(function () use ($content) {
public function create($content, $favorite=null) {
return $this->respond(function () use ($content, $favorite) {
$note = $this->service->create($this->userSession->getUser()->getUID());
return $this->service->update($note->getId(), $content, $this->userSession->getUser()->getUID());
return $this->updateData($note->getId(), $content, $favorite);
});
}

Expand All @@ -131,16 +132,27 @@ public function create($content) {
* @return DataResponse
*/
public function update($id, $content=null, $favorite=null) {
return $this->respond(function () use ($id, $content, $favorite) {
return $this->updateData($id, $content, $favorite);
});
}

/**
* Updates a note, used by create and update
* @param int $id
* @param string $content
* @param boolean $favorite
* @return Note
*/
private function updateData($id, $content, $favorite) {
if($favorite!==null) {
$this->service->favorite($id, $favorite, $this->userSession->getUser()->getUID());
}
return $this->respond(function () use ($id, $content) {
if($content===null) {
return $this->service->get($id, $this->userSession->getUser()->getUID());
} else {
return $this->service->update($id, $content, $this->userSession->getUser()->getUID());
}
});
if($content===null) {
return $this->service->get($id, $this->userSession->getUser()->getUID());
} else {
return $this->service->update($id, $content, $this->userSession->getUser()->getUID());
}
}


Expand Down