Skip to content
Merged
Show file tree
Hide file tree
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
38 changes: 26 additions & 12 deletions controller/notesapicontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ public function get($id, $exclude='') {
* @NoCSRFRequired
*
* @param string $content
* @param int $modified
* @param boolean $favorite
* @return DataResponse
*/
public function create($content) {
return $this->respond(function () use ($content) {
public function create($content, $modified=0, $favorite=null) {
return $this->respond(function () use ($content, $modified, $favorite) {
$note = $this->service->create($this->userId);
return $this->service->update($note->getId(), $content, $this->userId);
return $this->updateData($note->getId(), $content, $modified, $favorite);
});
}

Expand All @@ -125,23 +127,35 @@ public function create($content) {
*
* @param int $id
* @param string $content
* @param int $modified
* @param boolean $favorite
* @return DataResponse
*/
public function update($id, $content=null, $favorite=null) {
public function update($id, $content=null, $modified=0, $favorite=null) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this defaults to 0?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If modified is not stated in the request, the behavior is the same as before of my changes: the mtime of the note's file is set to the current date/time.

Therefore, my changes of the API are totally backward compatible. However, the API documentation has to be revised. But the wiki has not been transferred, yet.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return $this->respond(function () use ($id, $content, $modified, $favorite) {
return $this->updateData($id, $content, $modified, $favorite);
});
}

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


/**
* @NoAdminRequired
* @CORS
Expand Down
2 changes: 1 addition & 1 deletion js/public/app.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading