mirror of https://github.com/doccano/doccano.git
14 changed files with 0 additions and 796 deletions
Split View
Diff Options
-
192frontend/api/db/docs.json
-
34frontend/api/db/labels.json
-
12frontend/api/db/members.json
-
114frontend/api/db/projects.json
-
13frontend/api/db/stats.json
-
22frontend/api/db/users.json
-
23frontend/api/index.js
-
11frontend/api/routes/auth.js
-
132frontend/api/routes/docs.js
-
63frontend/api/routes/labels.js
-
64frontend/api/routes/members.js
-
79frontend/api/routes/projects.js
-
11frontend/api/routes/stats.js
-
26frontend/api/routes/users.js
@ -1,192 +0,0 @@ |
|||
{ |
|||
"count": 3250, |
|||
"next": "http://127.0.0.1:8000/v1/projects/2/docs?limit=5&offset=5", |
|||
"previous": null, |
|||
"results": [ |
|||
{ |
|||
"id": 4, |
|||
"text": "CRICKET - LEICESTERSHIRE TAKE OVER AT TOP AFTER INNINGS VICTORY .", |
|||
"annotations": [ |
|||
{ |
|||
"id": 5, |
|||
"prob": 0.0, |
|||
"label": 6, |
|||
"start_offset": 10, |
|||
"end_offset": 24, |
|||
"user": 1, |
|||
"document": 4, |
|||
"text": "This text is for seq2seq testing." |
|||
} |
|||
], |
|||
"meta": "{}", |
|||
"annotation_approver": null |
|||
}, |
|||
{ |
|||
"id": 5, |
|||
"text": "LONDON 1996-08-30", |
|||
"annotations": [ |
|||
{ |
|||
"id": 6, |
|||
"prob": 0.0, |
|||
"label": 4, |
|||
"start_offset": 0, |
|||
"end_offset": 6, |
|||
"user": 1, |
|||
"document": 5 |
|||
} |
|||
], |
|||
"meta": "{}", |
|||
"annotation_approver": null |
|||
}, |
|||
{ |
|||
"id": 6, |
|||
"text": "West Indian all-rounder Phil Simmons took four for 38 on Friday as Leicestershire beat Somerset by an innings and 39 runs in two days to take over at the head of the county championship .", |
|||
"annotations": [ |
|||
{ |
|||
"id": 7, |
|||
"prob": 0.0, |
|||
"label": 5, |
|||
"start_offset": 0, |
|||
"end_offset": 11, |
|||
"user": 1, |
|||
"document": 6 |
|||
}, |
|||
{ |
|||
"id": 9, |
|||
"prob": 0.0, |
|||
"label": 6, |
|||
"start_offset": 67, |
|||
"end_offset": 81, |
|||
"user": 1, |
|||
"document": 6 |
|||
}, |
|||
{ |
|||
"id": 10, |
|||
"prob": 0.0, |
|||
"label": 6, |
|||
"start_offset": 87, |
|||
"end_offset": 95, |
|||
"user": 1, |
|||
"document": 6 |
|||
}, |
|||
{ |
|||
"id": 8, |
|||
"prob": 0.0, |
|||
"label": 7, |
|||
"start_offset": 24, |
|||
"end_offset": 36, |
|||
"user": 1, |
|||
"document": 6 |
|||
} |
|||
], |
|||
"meta": "{}", |
|||
"annotation_approver": null |
|||
}, |
|||
{ |
|||
"id": 7, |
|||
"text": "Their stay on top , though , may be short-lived as title rivals Essex , Derbyshire and Surrey all closed in on victory while Kent made up for lost time in their rain-affected match against Nottinghamshire .", |
|||
"annotations": [ |
|||
{ |
|||
"id": 11, |
|||
"prob": 0.0, |
|||
"label": 6, |
|||
"start_offset": 64, |
|||
"end_offset": 69, |
|||
"user": 1, |
|||
"document": 7 |
|||
}, |
|||
{ |
|||
"id": 12, |
|||
"prob": 0.0, |
|||
"label": 6, |
|||
"start_offset": 72, |
|||
"end_offset": 82, |
|||
"user": 1, |
|||
"document": 7 |
|||
}, |
|||
{ |
|||
"id": 13, |
|||
"prob": 0.0, |
|||
"label": 6, |
|||
"start_offset": 87, |
|||
"end_offset": 93, |
|||
"user": 1, |
|||
"document": 7 |
|||
}, |
|||
{ |
|||
"id": 14, |
|||
"prob": 0.0, |
|||
"label": 6, |
|||
"start_offset": 125, |
|||
"end_offset": 129, |
|||
"user": 1, |
|||
"document": 7 |
|||
}, |
|||
{ |
|||
"id": 15, |
|||
"prob": 0.0, |
|||
"label": 6, |
|||
"start_offset": 189, |
|||
"end_offset": 204, |
|||
"user": 1, |
|||
"document": 7 |
|||
} |
|||
], |
|||
"meta": "{}", |
|||
"annotation_approver": null |
|||
}, |
|||
{ |
|||
"id": 8, |
|||
"text": "After bowling Somerset out for 83 on the opening morning at Grace Road , Leicestershire extended their first innings by 94 runs before being bowled out for 296 with England discard Andy Caddick taking three for 83 .", |
|||
"annotations": [ |
|||
{ |
|||
"id": 17, |
|||
"prob": 0.0, |
|||
"label": 4, |
|||
"start_offset": 60, |
|||
"end_offset": 70, |
|||
"user": 1, |
|||
"document": 8 |
|||
}, |
|||
{ |
|||
"id": 19, |
|||
"prob": 0.0, |
|||
"label": 4, |
|||
"start_offset": 165, |
|||
"end_offset": 172, |
|||
"user": 1, |
|||
"document": 8 |
|||
}, |
|||
{ |
|||
"id": 16, |
|||
"prob": 0.0, |
|||
"label": 6, |
|||
"start_offset": 14, |
|||
"end_offset": 22, |
|||
"user": 1, |
|||
"document": 8 |
|||
}, |
|||
{ |
|||
"id": 18, |
|||
"prob": 0.0, |
|||
"label": 6, |
|||
"start_offset": 73, |
|||
"end_offset": 87, |
|||
"user": 1, |
|||
"document": 8 |
|||
}, |
|||
{ |
|||
"id": 20, |
|||
"prob": 0.0, |
|||
"label": 7, |
|||
"start_offset": 181, |
|||
"end_offset": 193, |
|||
"user": 1, |
|||
"document": 8 |
|||
} |
|||
], |
|||
"meta": "{}", |
|||
"annotation_approver": null |
|||
} |
|||
] |
|||
} |
@ -1,34 +0,0 @@ |
|||
[ |
|||
{ |
|||
"id": 4, |
|||
"text": "LOC", |
|||
"prefix_key": null, |
|||
"suffix_key": "l", |
|||
"background_color": "#7c20e0", |
|||
"text_color": "#ffffff" |
|||
}, |
|||
{ |
|||
"id": 5, |
|||
"text": "MISC", |
|||
"prefix_key": null, |
|||
"suffix_key": "m", |
|||
"background_color": "#fbb028", |
|||
"text_color": "#000000" |
|||
}, |
|||
{ |
|||
"id": 6, |
|||
"text": "ORG", |
|||
"prefix_key": null, |
|||
"suffix_key": "o", |
|||
"background_color": "#e6d176", |
|||
"text_color": "#000000" |
|||
}, |
|||
{ |
|||
"id": 7, |
|||
"text": "PER", |
|||
"prefix_key": null, |
|||
"suffix_key": "p", |
|||
"background_color": "#6a74b9", |
|||
"text_color": "#ffffff" |
|||
} |
|||
] |
@ -1,12 +0,0 @@ |
|||
[ |
|||
{ |
|||
"id": 1, |
|||
"username": "Barack Obama", |
|||
"role": "Admin" |
|||
}, |
|||
{ |
|||
"id": 2, |
|||
"username": "George W. Bush", |
|||
"role": "Member" |
|||
} |
|||
] |
@ -1,114 +0,0 @@ |
|||
[ |
|||
{ |
|||
"id": 1, |
|||
"name": "CoNLL 2003", |
|||
"description": "This is a project for NER.", |
|||
"guideline": "Please write annotation guideline.", |
|||
"users": [ |
|||
1 |
|||
], |
|||
"project_type": "SequenceLabeling", |
|||
"image": "/static/assets/images/cats/sequence_labeling.jpg", |
|||
"updated_at": "2019-07-09T06:19:29.789091Z", |
|||
"randomize_document_order": false, |
|||
"resourcetype": "SequenceLabelingProject" |
|||
}, |
|||
{ |
|||
"id": 2, |
|||
"name": "Test", |
|||
"description": "test", |
|||
"guideline": "Please write annotation guideline.", |
|||
"users": [ |
|||
1 |
|||
], |
|||
"project_type": "SequenceLabeling", |
|||
"image": "/static/assets/images/cats/sequence_labeling.jpg", |
|||
"updated_at": "2019-07-22T05:08:45.202301Z", |
|||
"randomize_document_order": false, |
|||
"resourcetype": "SequenceLabelingProject" |
|||
}, |
|||
{ |
|||
"id": 3, |
|||
"name": "Pane", |
|||
"description": "pane", |
|||
"guideline": "Please write annotation guideline.", |
|||
"users": [ |
|||
1 |
|||
], |
|||
"project_type": "DocumentClassification", |
|||
"image": "/static/assets/images/cats/text_classification.jpg", |
|||
"updated_at": "2019-07-22T05:12:52.843046Z", |
|||
"randomize_document_order": false, |
|||
"resourcetype": "TextClassificationProject" |
|||
}, |
|||
{ |
|||
"id": 4, |
|||
"name": "seq2seq", |
|||
"description": "test", |
|||
"guideline": "Please write annotation guideline.", |
|||
"users": [ |
|||
1 |
|||
], |
|||
"project_type": "Seq2seq", |
|||
"image": "/static/assets/images/cats/seq2seq.jpg", |
|||
"updated_at": "2019-07-29T06:35:28.705326Z", |
|||
"randomize_document_order": false, |
|||
"resourcetype": "Seq2seqProject" |
|||
}, |
|||
{ |
|||
"id": 5, |
|||
"name": "NLPBook", |
|||
"description": "nlp book用のプロジェクト", |
|||
"guideline": "Please write annotation guideline.", |
|||
"users": [ |
|||
1 |
|||
], |
|||
"project_type": "SequenceLabeling", |
|||
"image": "/static/assets/images/cats/sequence_labeling.jpg", |
|||
"updated_at": "2019-08-01T01:46:35.938419Z", |
|||
"randomize_document_order": false, |
|||
"resourcetype": "SequenceLabelingProject" |
|||
}, |
|||
{ |
|||
"id": 6, |
|||
"name": "test", |
|||
"description": "test", |
|||
"guideline": "Please write annotation guideline.", |
|||
"users": [ |
|||
1 |
|||
], |
|||
"project_type": "SequenceLabeling", |
|||
"image": "/static/assets/images/cats/sequence_labeling.jpg", |
|||
"updated_at": "2019-08-01T04:15:09.998495Z", |
|||
"randomize_document_order": false, |
|||
"resourcetype": "SequenceLabelingProject" |
|||
}, |
|||
{ |
|||
"id": 7, |
|||
"name": "neko", |
|||
"description": "kkk", |
|||
"guideline": "Please write annotation guideline.", |
|||
"users": [ |
|||
1 |
|||
], |
|||
"project_type": "SequenceLabeling", |
|||
"image": "/static/assets/images/cats/sequence_labeling.jpg", |
|||
"updated_at": "2019-08-19T05:53:00.026794Z", |
|||
"randomize_document_order": false, |
|||
"resourcetype": "SequenceLabelingProject" |
|||
}, |
|||
{ |
|||
"id": 8, |
|||
"name": "classification", |
|||
"description": "nekoneko", |
|||
"guideline": "Please write annotation guideline.", |
|||
"users": [ |
|||
1 |
|||
], |
|||
"project_type": "DocumentClassification", |
|||
"image": "/static/assets/images/cats/text_classification.jpg", |
|||
"updated_at": "2019-08-21T02:49:48.790813Z", |
|||
"randomize_document_order": false, |
|||
"resourcetype": "TextClassificationProject" |
|||
} |
|||
] |
@ -1,13 +0,0 @@ |
|||
{ |
|||
"label": { |
|||
"LOC": 1838, |
|||
"MISC": 922, |
|||
"ORG": 1340, |
|||
"PER": 1842 |
|||
}, |
|||
"user": { |
|||
"hironsan": 5942 |
|||
}, |
|||
"total": 3250, |
|||
"remaining": 645 |
|||
} |
@ -1,22 +0,0 @@ |
|||
[ |
|||
{ |
|||
"id": 1, |
|||
"username": "Barack Obama" |
|||
}, |
|||
{ |
|||
"id": 2, |
|||
"username": "George W. Bush" |
|||
}, |
|||
{ |
|||
"id": 3, |
|||
"username": "Bill Clinton" |
|||
}, |
|||
{ |
|||
"id": 4, |
|||
"username": "Donald Trump" |
|||
}, |
|||
{ |
|||
"id": 5, |
|||
"username": "George H. W. Bush" |
|||
} |
|||
] |
@ -1,23 +0,0 @@ |
|||
const express = require('express') |
|||
const app = express() |
|||
|
|||
const docs = require('./routes/docs') |
|||
const labels = require('./routes/labels') |
|||
const projects = require('./routes/projects') |
|||
const members = require('./routes/members') |
|||
const users = require('./routes/users') |
|||
const stats = require('./routes/stats') |
|||
const auth = require('./routes/auth') |
|||
|
|||
app.use('/auth', auth) |
|||
app.use('/users', users) |
|||
app.use('/projects', projects) |
|||
app.use('/projects/:project_id/statistics', stats) |
|||
app.use('/projects/:project_id/docs', docs) |
|||
app.use('/projects/:project_id/labels', labels) |
|||
app.use('/projects/:project_id/users', members) |
|||
|
|||
module.exports = { |
|||
path: '/v1', |
|||
handler: app |
|||
} |
@ -1,11 +0,0 @@ |
|||
const express = require('express') |
|||
const router = express.Router() |
|||
|
|||
// Get a token.
|
|||
router.get('/api-token-auth', (req, res) => { |
|||
res.json({ |
|||
token: '9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b' |
|||
}) |
|||
}) |
|||
|
|||
module.exports = router |
@ -1,132 +0,0 @@ |
|||
const fs = require('fs') |
|||
const express = require('express') |
|||
const router = express.Router() |
|||
const db = JSON.parse(fs.readFileSync('./api/db/docs.json', 'utf8')) |
|||
|
|||
// Get doc list.
|
|||
router.get('/', (req, res) => { |
|||
const q = req.query.q |
|||
if (q) { |
|||
// res.json(db.filter(item => item.text.toLowerCase().includes(q.toLowerCase())))
|
|||
res.json(db) |
|||
} else { |
|||
res.json(db) |
|||
} |
|||
}) |
|||
|
|||
// Create a doc.
|
|||
router.post('/', (req, res) => { |
|||
const doc = { |
|||
id: db.results.reduce((x, y) => { return x.id > y.id ? x : y }).id + 1, |
|||
text: req.body.text |
|||
} |
|||
res.json(doc) |
|||
}) |
|||
|
|||
// Upload a file.
|
|||
router.post('/upload', (req, res) => { |
|||
const doc = { |
|||
id: db.results.reduce((x, y) => { return x.id > y.id ? x : y }).id + 1, |
|||
text: 'Uploaded Document', |
|||
meta: JSON.stringify({}), |
|||
annotations: [] |
|||
} |
|||
db.results.push(doc) |
|||
res.json(doc) |
|||
}) |
|||
|
|||
// Download a file.
|
|||
router.get('/download', (req, res) => { |
|||
res.json(db) |
|||
}) |
|||
|
|||
// Update a document partially.
|
|||
router.patch('/:docId', (req, res) => { |
|||
const docIndex = db.results.findIndex(item => item.id === parseInt(req.params.docId, 10)) |
|||
if (docIndex !== -1) { |
|||
Object.assign(db.results[docIndex], req.body) |
|||
res.json(db.results[docIndex]) |
|||
} else { |
|||
res.status(404).json({ detail: 'Not found.' }) |
|||
} |
|||
}) |
|||
|
|||
// Get a doc.
|
|||
router.get('/:docId', (req, res) => { |
|||
const doc = db.results.find(item => item.id === parseInt(req.params.docId, 10)) |
|||
if (doc) { |
|||
res.json(doc) |
|||
} else { |
|||
res.status(404).json({ detail: 'Not found.' }) |
|||
} |
|||
}) |
|||
|
|||
// Update a doc.
|
|||
router.put('/:docId', (req, res) => { |
|||
const docIndex = db.results.findIndex(item => item.id === parseInt(req.params.docId, 10)) |
|||
if (docIndex !== -1) { |
|||
db.results[docIndex] = req.body |
|||
res.json(db.results[docIndex]) |
|||
} else { |
|||
res.status(404).json({ detail: 'Not found.' }) |
|||
} |
|||
}) |
|||
|
|||
// Delete a doc.
|
|||
router.delete('/:docId', (req, res, next) => { |
|||
const doc = db.results.find(item => item.id === parseInt(req.params.docId, 10)) |
|||
if (doc) { |
|||
db.results = db.results.filter(item => item.id !== parseInt(req.params.docId, 10)) |
|||
res.json(doc) |
|||
} else { |
|||
res.status(404).json({ detail: 'Not found.' }) |
|||
} |
|||
}) |
|||
|
|||
// Add an annotation.
|
|||
router.post('/:docId/annotations', (req, res, next) => { |
|||
const doc = db.results.find(item => item.id === parseInt(req.params.docId, 10)) |
|||
if (doc) { |
|||
const annotation = { |
|||
id: Math.floor(Math.random() * 10000), |
|||
label: req.body.label, |
|||
start_offset: req.body.start_offset, |
|||
end_offset: req.body.end_offset, |
|||
user: 1, |
|||
document: parseInt(req.params.docId, 10), |
|||
text: req.body.text |
|||
} |
|||
doc.annotations.push(annotation) |
|||
res.json(annotation) |
|||
} else { |
|||
res.status(404).json({ detail: 'Not found.' }) |
|||
} |
|||
}) |
|||
|
|||
// Delete an annotation.
|
|||
router.delete('/:docId/annotations/:annotationId', (req, res, next) => { |
|||
const doc = db.results.find(item => item.id === parseInt(req.params.docId, 10)) |
|||
const docIndex = db.results.findIndex(item => item.id === parseInt(req.params.docId, 10)) |
|||
if (doc) { |
|||
const annotation = doc.annotations.find(item => item.id === parseInt(req.params.annotationId, 10)) |
|||
doc.annotations = doc.annotations.filter(item => item.id !== parseInt(req.params.annotationId, 10)) |
|||
db.results[docIndex] = doc |
|||
res.json(annotation) |
|||
} else { |
|||
res.status(404).json({ detail: 'Not found.' }) |
|||
} |
|||
}) |
|||
|
|||
// Update an annotation.
|
|||
router.patch('/:docId/annotations/:annotationId', (req, res, next) => { |
|||
const docIndex = db.results.findIndex(item => item.id === parseInt(req.params.docId, 10)) |
|||
if (docIndex !== -1) { |
|||
const doc = db.results[docIndex] |
|||
const annotationIndex = doc.annotations.findIndex(item => item.id === parseInt(req.params.annotationId, 10)) |
|||
Object.assign(db.results[docIndex].annotations[annotationIndex], req.body) |
|||
res.json(db.results[docIndex].annotations[annotationIndex]) |
|||
} else { |
|||
res.status(404).json({ detail: 'Not found.' }) |
|||
} |
|||
}) |
|||
module.exports = router |
@ -1,63 +0,0 @@ |
|||
const fs = require('fs') |
|||
const express = require('express') |
|||
const router = express.Router() |
|||
let db = JSON.parse(fs.readFileSync('./api/db/labels.json', 'utf8')) |
|||
|
|||
// Get label list.
|
|||
router.get('/', (req, res) => { |
|||
const q = req.query.q |
|||
if (q) { |
|||
res.json(db.filter(item => item.text.toLowerCase().includes(q.toLowerCase()))) |
|||
} else { |
|||
res.json(db) |
|||
} |
|||
}) |
|||
|
|||
// Create a label.
|
|||
router.post('/', (req, res) => { |
|||
const label = { |
|||
id: db.reduce((x, y) => { return x.id > y.id ? x : y }).id + 1, |
|||
text: req.body.text, |
|||
prefix_key: req.body.prefix_key, |
|||
suffix_key: req.body.suffix_key, |
|||
background_color: req.body.background_color, |
|||
text_color: '#ffffff' |
|||
} |
|||
db.push(label) |
|||
res.json(label) |
|||
}) |
|||
|
|||
// Get a label.
|
|||
router.get('/:labelId', (req, res) => { |
|||
const label = db.find(item => item.id === parseInt(req.params.labelId, 10)) |
|||
if (label) { |
|||
res.json(label) |
|||
} else { |
|||
res.status(404).json({ detail: 'Not found.' }) |
|||
} |
|||
}) |
|||
|
|||
// Update a label.
|
|||
router.patch('/:labelId', (req, res) => { |
|||
const labelIndex = db.findIndex(item => item.id === parseInt(req.params.labelId, 10)) |
|||
if (labelIndex !== -1) { |
|||
// db[labelIndex] = req.body
|
|||
Object.assign(db[labelIndex], req.body) |
|||
res.json(db[labelIndex]) |
|||
} else { |
|||
res.status(404).json({ detail: 'Not found.' }) |
|||
} |
|||
}) |
|||
|
|||
// Delete a label.
|
|||
router.delete('/:labelId', (req, res, next) => { |
|||
const label = db.find(item => item.id === parseInt(req.params.labelId, 10)) |
|||
if (label) { |
|||
db = db.filter(item => item.id !== parseInt(req.params.labelId, 10)) |
|||
res.json(label) |
|||
} else { |
|||
res.status(404).json({ detail: 'Not found.' }) |
|||
} |
|||
}) |
|||
|
|||
module.exports = router |
@ -1,64 +0,0 @@ |
|||
const fs = require('fs') |
|||
const bodyParser = require('body-parser') |
|||
const express = require('express') |
|||
const router = express.Router() |
|||
let db = JSON.parse(fs.readFileSync('./api/db/members.json', 'utf8')) |
|||
const users = JSON.parse(fs.readFileSync('./api/db/users.json', 'utf8')) |
|||
router.use(bodyParser.json()) |
|||
router.use(bodyParser.urlencoded({ extended: true })) |
|||
|
|||
// Get project user list.
|
|||
router.get('/', (req, res) => { |
|||
const q = req.query.q |
|||
if (q) { |
|||
res.json(db.filter(item => item.name.toLowerCase().includes(q.toLowerCase()))) |
|||
} else { |
|||
res.json(db) |
|||
} |
|||
}) |
|||
|
|||
// Add a project user.
|
|||
router.post('/', (req, res) => { |
|||
const user = users.find(item => item.id === parseInt(req.body.id, 10)) |
|||
const member = { |
|||
...user, |
|||
role: req.body.role |
|||
} |
|||
db.push(member) |
|||
res.json(member) |
|||
}) |
|||
|
|||
// Update a project user.
|
|||
router.put('/:userId', (req, res) => { |
|||
const projectIndex = db.findIndex(item => item.id === parseInt(req.params.userId, 10)) |
|||
if (projectIndex !== -1) { |
|||
db[projectIndex] = req.body |
|||
res.json(db[projectIndex]) |
|||
} else { |
|||
res.status(404).json({ detail: 'Not found.' }) |
|||
} |
|||
}) |
|||
|
|||
// Partially update a project user.
|
|||
router.patch('/:userId', (req, res) => { |
|||
const projectIndex = db.findIndex(item => item.id === parseInt(req.params.userId, 10)) |
|||
if (projectIndex !== -1) { |
|||
db[projectIndex].role = req.body.role |
|||
res.json(db[projectIndex]) |
|||
} else { |
|||
res.status(404).json({ detail: 'Not found.' }) |
|||
} |
|||
}) |
|||
|
|||
// Delete a project user.
|
|||
router.delete('/:userId', (req, res, next) => { |
|||
const project = db.find(item => item.id === parseInt(req.params.userId, 10)) |
|||
if (project) { |
|||
db = db.filter(item => item.id !== parseInt(req.params.userId, 10)) |
|||
res.json(project) |
|||
} else { |
|||
res.status(404).json({ detail: 'Not found.' }) |
|||
} |
|||
}) |
|||
|
|||
module.exports = router |
@ -1,79 +0,0 @@ |
|||
const fs = require('fs') |
|||
const bodyParser = require('body-parser') |
|||
const express = require('express') |
|||
const router = express.Router() |
|||
let db = JSON.parse(fs.readFileSync('./api/db/projects.json', 'utf8')) |
|||
router.use(bodyParser.json()) |
|||
router.use(bodyParser.urlencoded({ extended: true })) |
|||
|
|||
// Get project list.
|
|||
router.get('/', (req, res) => { |
|||
const q = req.query.q |
|||
if (q) { |
|||
res.json(db.filter(item => item.name.toLowerCase().includes(q.toLowerCase()))) |
|||
} else { |
|||
res.json(db) |
|||
} |
|||
}) |
|||
|
|||
// Create a project.
|
|||
router.post('/', (req, res) => { |
|||
const project = { |
|||
id: db.reduce((x, y) => { return x.id > y.id ? x : y }).id + 1, |
|||
name: req.body.name, |
|||
description: req.body.description, |
|||
guideline: 'Please write annotation guideline.', |
|||
users: [1], |
|||
project_type: req.body.project_type, |
|||
image: '/static/assets/images/cats/text_classification.jpg', |
|||
updated_at: '2019-08-21T02:49:48.790813Z', |
|||
randomize_document_order: false |
|||
} |
|||
db.push(project) |
|||
res.json(project) |
|||
}) |
|||
|
|||
// Get a project.
|
|||
router.get('/:projectId', (req, res) => { |
|||
const project = db.find(item => item.id === parseInt(req.params.projectId, 10)) |
|||
if (project) { |
|||
res.json(project) |
|||
} else { |
|||
res.status(404).json({ detail: 'Not found.' }) |
|||
} |
|||
}) |
|||
|
|||
// Update a project.
|
|||
router.put('/:projectId', (req, res) => { |
|||
const projectIndex = db.findIndex(item => item.id === parseInt(req.params.projectId, 10)) |
|||
if (projectIndex !== -1) { |
|||
db[projectIndex] = req.body |
|||
res.json(db[projectIndex]) |
|||
} else { |
|||
res.status(404).json({ detail: 'Not found.' }) |
|||
} |
|||
}) |
|||
|
|||
// Partially update a project user.
|
|||
router.patch('/:projectId', (req, res) => { |
|||
const projectIndex = db.findIndex(item => item.id === parseInt(req.params.projectId, 10)) |
|||
if (projectIndex !== -1) { |
|||
Object.assign(db[projectIndex], req.body) |
|||
res.json(db[projectIndex]) |
|||
} else { |
|||
res.status(404).json({ detail: 'Not found.' }) |
|||
} |
|||
}) |
|||
|
|||
// Delete a project.
|
|||
router.delete('/:projectId', (req, res, next) => { |
|||
const project = db.find(item => item.id === parseInt(req.params.projectId, 10)) |
|||
if (project) { |
|||
db = db.filter(item => item.id !== parseInt(req.params.projectId, 10)) |
|||
res.json(project) |
|||
} else { |
|||
res.status(404).json({ detail: 'Not found.' }) |
|||
} |
|||
}) |
|||
|
|||
module.exports = router |
@ -1,11 +0,0 @@ |
|||
const fs = require('fs') |
|||
const express = require('express') |
|||
const router = express.Router() |
|||
const db = JSON.parse(fs.readFileSync('./api/db/stats.json', 'utf8')) |
|||
|
|||
// Get statistics.
|
|||
router.get('/', (req, res) => { |
|||
res.json(db) |
|||
}) |
|||
|
|||
module.exports = router |
@ -1,26 +0,0 @@ |
|||
const fs = require('fs') |
|||
const express = require('express') |
|||
const router = express.Router() |
|||
const db = JSON.parse(fs.readFileSync('./api/db/users.json', 'utf8')) |
|||
|
|||
// Get user list.
|
|||
router.get('/', (req, res) => { |
|||
const q = req.query.q |
|||
if (q) { |
|||
res.json(db.filter(item => item.username.toLowerCase().includes(q.toLowerCase()))) |
|||
} else { |
|||
res.json(db) |
|||
} |
|||
}) |
|||
|
|||
// Get a user.
|
|||
router.get('/:userId', (req, res) => { |
|||
const user = db.find(item => item.id === parseInt(req.params.userId, 10)) |
|||
if (user) { |
|||
res.json(user) |
|||
} else { |
|||
res.status(404).json({ detail: 'Not found.' }) |
|||
} |
|||
}) |
|||
|
|||
module.exports = router |
Write
Preview
Loading…
Cancel
Save