Skip to content

Commit 6624e70

Browse files
committed
implemented removing tags from documents
DELETE `/doc/{id}/tag/{lable}`
1 parent 835d3ab commit 6624e70

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Parameterizable tags can only be added to a document with a value assigned. By `
8888
| `/doc/{id}/comment` | GET | Get comments | - | - | - |
8989
| `/doc/{id}/tag` | POST | Add a tag to document | Tag object / See above | - | Implemented |
9090
| `/doc/{id}/tag` | GET | Get tags of document | - | Array of tag objects | Implemented |
91-
| `/doc/{id}/tag/{tagLabel}` | DELETE | Remove tag from document | - | - | - |
91+
| `/doc/{id}/tag/{tagLabel}` | DELETE | Remove tag from document | - | - | Implemented |
9292
| `/doc/{id}/title` | PUT | Set document title | `{"title": "the_Title"}` | - | Implemented |
9393
| `/doc/{id}/title` | GET | Get document title | - | `{"title": "the_Title"}` | Implemented |
9494
| `/doc/{id}/title` | DELETE | Reset document title | - | - | Implemented |

lib/metadeleter.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function deleteTitle(id) {
1616
})
1717
}
1818

19-
function deleteTag(label) {
19+
function deleteTag(label,id) {
2020
return fetch("http://fuseki:3030/3DOC/update", {
2121
method: "POST",
2222
headers: {
@@ -28,14 +28,19 @@ function deleteTag(label) {
2828
'PREFIX tridoc: <http://vocab.tridoc.me/>\n' +
2929
'WITH <http://3doc/meta>\n' +
3030
'DELETE {\n' +
31-
' ?ptag ?p ?o .\n' +
32-
' ?s1 ?p1 ?ptag\n' +
31+
(id ?
32+
' <http://3doc/data/' + id + '> tridoc:tag ?ptag \n'
33+
: ' ?ptag ?p ?o .\n' +
34+
' ?s ?p1 ?ptag \n'
35+
) +
3336
'}\n' +
3437
'WHERE {\n' +
3538
' ?ptag tridoc:parameterizableTag ?tag.\n' +
3639
' ?tag tridoc:label "' + label + '" .\n' +
3740
' OPTIONAL { ?ptag ?p ?o } \n' +
38-
' OPTIONAL { ?s1 ?p1 ?ptag } \n' +
41+
' OPTIONAL { \n' +
42+
(id ? ' <http://3doc/data/' + id + '> tridoc:tag ?ptag \n' : ' ?s ?p1 ?ptag \n') +
43+
' } \n' +
3944
'}'
4045
}).catch(e => console.log(e)).then(() => {
4146
return fetch("http://fuseki:3030/3DOC/update", {
@@ -49,13 +54,18 @@ function deleteTag(label) {
4954
'PREFIX tridoc: <http://vocab.tridoc.me/>\n' +
5055
'WITH <http://3doc/meta>\n' +
5156
'DELETE {\n' +
52-
' ?tag ?p ?o .\n' +
53-
' ?s1 ?p1 ?tag\n' +
57+
(id ?
58+
' <http://3doc/data/' + id + '> tridoc:tag ?tag\n'
59+
: ' ?tag ?p ?o .\n' +
60+
' ?s ?p1 ?tag\n'
61+
) +
5462
'}\n' +
5563
'WHERE {\n' +
5664
' ?tag tridoc:label "' + label + '" .\n' +
5765
' OPTIONAL { ?tag ?p ?o } \n' +
58-
' OPTIONAL { ?s1 ?p1 ?tag } \n' +
66+
' OPTIONAL { \n' +
67+
(id ? ' <http://3doc/data/' + id + '> ?p1 ?tag\n' : ' ?s ?p1 ?tag\n') +
68+
' } \n' +
5969
'}'
6070
})
6171
})

lib/server.js

+12
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ server.route({
170170
}
171171
});
172172

173+
server.route({
174+
method: 'DELETE',
175+
path: '/doc/{id}/tag/{label}',
176+
config: {
177+
handler: (request, h) => {
178+
var label = decodeURIComponent(request.params.label);
179+
var id = decodeURIComponent(request.params.id);
180+
return metaDeleter.deleteTag(label,id);
181+
}
182+
}
183+
});
184+
173185
server.route({
174186
method: 'PUT',
175187
path: '/doc/{id}/title',

0 commit comments

Comments
 (0)