diff --git a/src/etapi/attributes.js b/src/etapi/attributes.js index fddceb7ce..13c86e223 100644 --- a/src/etapi/attributes.js +++ b/src/etapi/attributes.js @@ -49,7 +49,7 @@ function register(router) { ru.route(router, 'delete' ,'/etapi/attributes/:attributeId', (req, res, next) => { const attribute = becca.getAttribute(req.params.attributeId); - if (!attribute) { + if (!attribute || attribute.isDeleted) { return res.sendStatus(204); } @@ -61,4 +61,4 @@ function register(router) { module.exports = { register -}; \ No newline at end of file +}; diff --git a/src/etapi/branches.js b/src/etapi/branches.js index 59a21c7bd..a9c9a64b7 100644 --- a/src/etapi/branches.js +++ b/src/etapi/branches.js @@ -57,7 +57,7 @@ function register(router) { ru.route(router, 'delete' ,'/etapi/branches/:branchId', (req, res, next) => { const branch = becca.getBranch(req.params.branchId); - if (!branch) { + if (!branch || branch.isDeleted) { return res.sendStatus(204); } diff --git a/src/etapi/notes.js b/src/etapi/notes.js index b12b3bd10..2ad7cc36f 100644 --- a/src/etapi/notes.js +++ b/src/etapi/notes.js @@ -13,19 +13,6 @@ function register(router) { res.json(mappers.mapNoteToPojo(note)); }); - ru.route(router, 'get', '/etapi/notes/:noteId/content', (req, res, next) => { - const note = ru.getAndCheckNote(req.params.noteId); - - const filename = utils.formatDownloadTitle(note.title, note.type, note.mime); - - res.setHeader('Content-Disposition', utils.getContentDisposition(filename)); - - res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); - res.setHeader('Content-Type', note.mime); - - res.send(note.getContent()); - }); - ru.route(router, 'post' ,'/etapi/create-note', (req, res, next) => { const params = req.body; @@ -67,7 +54,7 @@ function register(router) { const note = becca.getNote(noteId); - if (!note) { + if (!note || note.isDeleted) { return res.sendStatus(204); } @@ -75,6 +62,27 @@ function register(router) { res.sendStatus(204); }); + + ru.route(router, 'get', '/etapi/notes/:noteId/content', (req, res, next) => { + const note = ru.getAndCheckNote(req.params.noteId); + + const filename = utils.formatDownloadTitle(note.title, note.type, note.mime); + + res.setHeader('Content-Disposition', utils.getContentDisposition(filename)); + + res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); + res.setHeader('Content-Type', note.mime); + + res.send(note.getContent()); + }); + + ru.route(router, 'put', '/etapi/notes/:noteId/content', (req, res, next) => { + const note = ru.getAndCheckNote(req.params.noteId); + + note.setContent(req.body); + + return res.sendStatus(204); + }); } module.exports = { diff --git a/test-etapi/delete-attribute.http b/test-etapi/delete-attribute.http index d1e80269b..32f777b07 100644 --- a/test-etapi/delete-attribute.http +++ b/test-etapi/delete-attribute.http @@ -46,11 +46,17 @@ DELETE {{triliumHost}}/etapi/attributes/{{createdAttributeId}} > {% client.assert(response.status === 204, "Response status is not 204"); %} +### repeat the DELETE request to test the idempotency + +DELETE {{triliumHost}}/etapi/attributes/{{createdAttributeId}} + +> {% client.assert(response.status === 204, "Response status is not 204"); %} + ### GET {{triliumHost}}/etapi/attributes/{{createdAttributeId}} -> {% - client.assert(response.status === 404, "Response status is not 404"); - client.assert(response.body.code == "ATTRIBUTE_NOT_FOUND"); -%} \ No newline at end of file +> {% + client.assert(response.status === 404, "Response status is not 404"); + client.assert(response.body.code === "ATTRIBUTE_NOT_FOUND"); +%} diff --git a/test-etapi/delete-cloned-branch.http b/test-etapi/delete-cloned-branch.http index f140b2c52..32ea133e7 100644 --- a/test-etapi/delete-cloned-branch.http +++ b/test-etapi/delete-cloned-branch.http @@ -49,13 +49,19 @@ DELETE {{triliumHost}}/etapi/branches/{{createdBranchId}} > {% client.assert(response.status === 204, "Response status is not 204"); %} +### repeat the DELETE request to test the idempotency + +DELETE {{triliumHost}}/etapi/branches/{{createdBranchId}} + +> {% client.assert(response.status === 204, "Response status is not 204"); %} + ### GET {{triliumHost}}/etapi/branches/{{createdBranchId}} -> {% - client.assert(response.status === 404, "Response status is not 404"); - client.assert(response.body.code == "BRANCH_NOT_FOUND"); +> {% + client.assert(response.status === 404, "Response status is not 404"); + client.assert(response.body.code === "BRANCH_NOT_FOUND"); %} ### @@ -68,4 +74,4 @@ GET {{triliumHost}}/etapi/branches/{{clonedBranchId}} GET {{triliumHost}}/etapi/notes/{{createdNoteId}} -> {% client.assert(response.status === 200, "Response status is not 200"); %} \ No newline at end of file +> {% client.assert(response.status === 200, "Response status is not 200"); %} diff --git a/test-etapi/delete-note-with-all-branches.http b/test-etapi/delete-note-with-all-branches.http index 15f985fc8..bae8890db 100644 --- a/test-etapi/delete-note-with-all-branches.http +++ b/test-etapi/delete-note-with-all-branches.http @@ -70,21 +70,27 @@ DELETE {{triliumHost}}/etapi/notes/{{createdNoteId}} > {% client.assert(response.status === 204, "Response status is not 204"); %} +### repeat the DELETE request to test the idempotency + +DELETE {{triliumHost}}/etapi/notes/{{createdNoteId}} + +> {% client.assert(response.status === 204, "Response status is not 204"); %} + ### GET {{triliumHost}}/etapi/branches/{{createdBranchId}} -> {% - client.assert(response.status === 404, "Response status is not 404"); - client.assert(response.body.code == "BRANCH_NOT_FOUND"); +> {% + client.assert(response.status === 404, "Response status is not 404"); + client.assert(response.body.code === "BRANCH_NOT_FOUND"); %} ### GET {{triliumHost}}/etapi/branches/{{clonedBranchId}} -> {% - client.assert(response.status === 404, "Response status is not 404"); +> {% + client.assert(response.status === 404, "Response status is not 404"); client.assert(response.body.code == "BRANCH_NOT_FOUND"); %} @@ -92,16 +98,16 @@ GET {{triliumHost}}/etapi/branches/{{clonedBranchId}} GET {{triliumHost}}/etapi/notes/{{createdNoteId}} -> {% - client.assert(response.status === 404, "Response status is not 404"); - client.assert(response.body.code == "NOTE_NOT_FOUND"); +> {% + client.assert(response.status === 404, "Response status is not 404"); + client.assert(response.body.code === "NOTE_NOT_FOUND"); %} ### GET {{triliumHost}}/etapi/attributes/{{createdAttributeId}} -> {% - client.assert(response.status === 404, "Response status is not 404"); - client.assert(response.body.code == "ATTRIBUTE_NOT_FOUND"); -%} \ No newline at end of file +> {% + client.assert(response.status === 404, "Response status is not 404"); + client.assert(response.body.code === "ATTRIBUTE_NOT_FOUND"); +%} diff --git a/test-etapi/put-note-content.http b/test-etapi/put-note-content.http new file mode 100644 index 000000000..a449da360 --- /dev/null +++ b/test-etapi/put-note-content.http @@ -0,0 +1,25 @@ +POST {{triliumHost}}/etapi/create-note +Content-Type: application/json + +{ + "parentNoteId": "root", + "title": "Hello", + "type": "code", + "mime": "text/plain", + "content": "Hi there!" +} + +> {% client.global.set("createdNoteId", response.body.note.noteId); %} + +### + +PUT {{triliumHost}}/etapi/notes/{{createdNoteId}}/content +Content-Type: text/plain + +Changed content + +### + +GET {{triliumHost}}/etapi/notes/{{createdNoteId}}/content + +> {% client.assert(response.body === "Changed content"); %}