author | ymh <ymh.work@gmail.com> |
Sat, 06 Aug 2016 21:29:33 +0700 | |
changeset 261 | 02e2396bcbbc |
parent 245 | c9dd78a43b07 |
child 274 | 53a6985443f8 |
permissions | -rw-r--r-- |
173 | 1 |
import ENV from 'app-client/config/environment'; |
2 |
import _ from 'lodash/lodash'; |
|
3 |
import * as constants from 'corpus-common-addon/utils/constants'; |
|
4 |
||
5 |
export default function() { |
|
6 |
||
7 |
// These comments are here to help you get started. Feel free to delete them. |
|
8 |
||
9 |
/* |
|
10 |
Config (with defaults). |
|
11 |
||
12 |
Note: these only affect routes defined *after* them! |
|
13 |
*/ |
|
14 |
// this.urlPrefix = ''; // make this `http://localhost:8080`, for example, if your API is on a different server |
|
15 |
// this.namespace = ''; // make this `api`, for example, if your API is namespaced |
|
261
02e2396bcbbc
Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents:
245
diff
changeset
|
16 |
this.namespace = ENV.rootURL.replace(/\/$/,'')+'/api/v1'; |
173 | 17 |
// this.timing = 400; // delay for each request, automatically set to 0 during testing |
18 |
||
19 |
this.get('/documents', function({ documents }) { |
|
20 |
return this.serialize(documents.all(), 'sparse-document'); |
|
21 |
}); |
|
245
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
173
diff
changeset
|
22 |
|
173 | 23 |
this.get('/documents/:id', ({documents}, request) => { |
24 |
let id = decodeURIComponent(request.params.id); |
|
25 |
return documents.find(id); |
|
26 |
}); |
|
27 |
||
28 |
this.get('/documents/:id/transcript', ({transcripts}, request) => { |
|
29 |
let id = decodeURIComponent(request.params.id); |
|
30 |
return transcripts.find(id).transcript; |
|
31 |
}); |
|
32 |
||
33 |
this.get('/languages'); |
|
34 |
||
35 |
this.get('/themes'); |
|
36 |
||
37 |
this.get('/discourses'); |
|
38 |
||
39 |
this.get('/lexvo/:ids', ({lexvos}, request) => { |
|
40 |
var langIds = decodeURIComponent(request.params.ids); |
|
41 |
var resMap = _.reduce(langIds.split(','), function(res, id) { |
|
42 |
var fullId = id; |
|
43 |
if(!_.startsWith(fullId, constants.LEXVO_BASE_URL)) { |
|
44 |
fullId = constants.LEXVO_BASE_URL + id; |
|
45 |
} |
|
46 |
var lexvoRes = lexvos.find(fullId); |
|
47 |
res[id] = lexvoRes?lexvoRes.name:null; |
|
48 |
return res; |
|
49 |
}, {}); |
|
50 |
return { |
|
51 |
'lexvoids': resMap |
|
52 |
}; |
|
53 |
}); |
|
54 |
||
55 |
this.get('/bnf/:ids', ({ bnfs }, request) => { |
|
56 |
var bnfIds = decodeURIComponent(request.params.ids); |
|
57 |
var resMap = _.reduce(bnfIds.split(','), function(res, id) { |
|
58 |
var fullId = id; |
|
59 |
if(_.startsWith(fullId, constants.BNF_BASE_URL)) { |
|
60 |
fullId = fullId.slice(constants.BNF_BASE_URL.length); |
|
61 |
} else if (_.startsWith(fullId, constants.BNF_ARK_BASE_URL)) { |
|
62 |
fullId = fullId.slice(constants.BNF_ARK_BASE_URL.length); |
|
63 |
} else if (!_.startsWith(fullId, constants.BNF_ARK_BASE_ID)) { |
|
64 |
fullId = constants.BNF_ARK_BASE_ID + fullId; |
|
65 |
} |
|
66 |
var bnfRes = bnfs.find(fullId); |
|
67 |
res[id] = bnfRes?bnfRes.label:null; |
|
68 |
return res; |
|
69 |
}, {}); |
|
70 |
return { |
|
71 |
'bnfids': resMap |
|
72 |
}; |
|
73 |
}); |
|
74 |
||
75 |
||
76 |
} |