Skip to content

Commit

Permalink
implemented removing tags from documents
Browse files Browse the repository at this point in the history
DELETE `/doc/{id}/tag/{lable}`
  • Loading branch information
nleanba committed Sep 29, 2018
1 parent 835d3ab commit 6624e70
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Parameterizable tags can only be added to a document with a value assigned. By `
| `/doc/{id}/comment` | GET | Get comments | - | - | - |
| `/doc/{id}/tag` | POST | Add a tag to document | Tag object / See above | - | Implemented |
| `/doc/{id}/tag` | GET | Get tags of document | - | Array of tag objects | Implemented |
| `/doc/{id}/tag/{tagLabel}` | DELETE | Remove tag from document | - | - | - |
| `/doc/{id}/tag/{tagLabel}` | DELETE | Remove tag from document | - | - | Implemented |
| `/doc/{id}/title` | PUT | Set document title | `{"title": "the_Title"}` | - | Implemented |
| `/doc/{id}/title` | GET | Get document title | - | `{"title": "the_Title"}` | Implemented |
| `/doc/{id}/title` | DELETE | Reset document title | - | - | Implemented |
Expand Down
24 changes: 17 additions & 7 deletions lib/metadeleter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function deleteTitle(id) {
})
}

function deleteTag(label) {
function deleteTag(label,id) {
return fetch("http://fuseki:3030/3DOC/update", {
method: "POST",
headers: {
Expand All @@ -28,14 +28,19 @@ function deleteTag(label) {
'PREFIX tridoc: <http://vocab.tridoc.me/>\n' +
'WITH <http://3doc/meta>\n' +
'DELETE {\n' +
' ?ptag ?p ?o .\n' +
' ?s1 ?p1 ?ptag\n' +
(id ?
' <http://3doc/data/' + id + '> tridoc:tag ?ptag \n'
: ' ?ptag ?p ?o .\n' +
' ?s ?p1 ?ptag \n'
) +
'}\n' +
'WHERE {\n' +
' ?ptag tridoc:parameterizableTag ?tag.\n' +
' ?tag tridoc:label "' + label + '" .\n' +
' OPTIONAL { ?ptag ?p ?o } \n' +
' OPTIONAL { ?s1 ?p1 ?ptag } \n' +
' OPTIONAL { \n' +
(id ? ' <http://3doc/data/' + id + '> tridoc:tag ?ptag \n' : ' ?s ?p1 ?ptag \n') +
' } \n' +
'}'
}).catch(e => console.log(e)).then(() => {
return fetch("http://fuseki:3030/3DOC/update", {
Expand All @@ -49,13 +54,18 @@ function deleteTag(label) {
'PREFIX tridoc: <http://vocab.tridoc.me/>\n' +
'WITH <http://3doc/meta>\n' +
'DELETE {\n' +
' ?tag ?p ?o .\n' +
' ?s1 ?p1 ?tag\n' +
(id ?
' <http://3doc/data/' + id + '> tridoc:tag ?tag\n'
: ' ?tag ?p ?o .\n' +
' ?s ?p1 ?tag\n'
) +
'}\n' +
'WHERE {\n' +
' ?tag tridoc:label "' + label + '" .\n' +
' OPTIONAL { ?tag ?p ?o } \n' +
' OPTIONAL { ?s1 ?p1 ?tag } \n' +
' OPTIONAL { \n' +
(id ? ' <http://3doc/data/' + id + '> ?p1 ?tag\n' : ' ?s ?p1 ?tag\n') +
' } \n' +
'}'
})
})
Expand Down
12 changes: 12 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@ server.route({
}
});

server.route({
method: 'DELETE',
path: '/doc/{id}/tag/{label}',
config: {
handler: (request, h) => {
var label = decodeURIComponent(request.params.label);
var id = decodeURIComponent(request.params.id);
return metaDeleter.deleteTag(label,id);
}
}
});

server.route({
method: 'PUT',
path: '/doc/{id}/title',
Expand Down

0 comments on commit 6624e70

Please sign in to comment.