mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 15:03:07 +00:00
Add support for Communities
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { COMMUNITIES } from "./communities";
|
||||
const util = require('util');
|
||||
const { Router } = require('express');
|
||||
|
||||
@@ -51,6 +52,67 @@ export function createMockApi() {
|
||||
|
||||
let router = Router();
|
||||
|
||||
router.route('/communities')
|
||||
.get(function(req, res) {
|
||||
console.log('GET');
|
||||
// 70ms latency
|
||||
setTimeout(function() {
|
||||
res.json(toHALResponse(req, COMMUNITIES));
|
||||
}, 0);
|
||||
|
||||
// })
|
||||
// .post(function(req, res) {
|
||||
// console.log('POST', util.inspect(req.body, { colors: true }));
|
||||
// let community = req.body;
|
||||
// if (community) {
|
||||
// COMMUNITIES.push({
|
||||
// value: community.value,
|
||||
// created_at: new Date(),
|
||||
// completed: community.completed,
|
||||
// id: COMMUNITY_COUNT++
|
||||
// });
|
||||
// return res.json(community);
|
||||
// }
|
||||
//
|
||||
// return res.end();
|
||||
});
|
||||
|
||||
router.param('community_id', function(req, res, next, community_id) {
|
||||
// ensure correct prop type
|
||||
let id = req.params.community_id;
|
||||
try {
|
||||
req.community_id = id;
|
||||
req.community = COMMUNITIES.find((community) => {
|
||||
return community.id === id;
|
||||
});
|
||||
next();
|
||||
} catch (e) {
|
||||
next(new Error('failed to load community'));
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/communities/:community_id')
|
||||
.get(function(req, res) {
|
||||
// console.log('GET', util.inspect(req.community.id, { colors: true }));
|
||||
res.json(toHALResponse(req, req.community));
|
||||
// })
|
||||
// .put(function(req, res) {
|
||||
// console.log('PUT', util.inspect(req.body, { colors: true }));
|
||||
//
|
||||
// let index = COMMUNITIES.indexOf(req.community);
|
||||
// let community = COMMUNITIES[index] = req.body;
|
||||
//
|
||||
// res.json(community);
|
||||
// })
|
||||
// .delete(function(req, res) {
|
||||
// console.log('DELETE', req.community_id);
|
||||
//
|
||||
// let index = COMMUNITIES.indexOf(req.community);
|
||||
// COMMUNITIES.splice(index, 1);
|
||||
//
|
||||
// res.json(req.community);
|
||||
});
|
||||
|
||||
router.route('/collections')
|
||||
.get(function(req, res) {
|
||||
console.log('GET');
|
||||
|
86
src/backend/communities.ts
Normal file
86
src/backend/communities.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
export const COMMUNITIES = [
|
||||
{
|
||||
"name": "Community 1",
|
||||
"handle": "10673/1",
|
||||
"id": "6631",
|
||||
"uuid": "83cd3281-f241-48be-9234-d876f8010d14",
|
||||
"type": "community",
|
||||
"metadata": [
|
||||
{
|
||||
"key": "dc.description",
|
||||
"value": "<p>This is the introductory text for the <em>Sample Community</em> on the DSpace Demonstration Site. It is editable by System or Community Administrators (of this Community).</p>\r\n<p><strong>DSpace Communities may contain one or more Sub-Communities or Collections (of Items).</strong></p>\r\n<p>This particular Community has its own logo (the <a href=\"http://www.duraspace.org/\">DuraSpace</a> logo).</p>",
|
||||
"language": null
|
||||
},
|
||||
{
|
||||
"key": "dc.description.abstract",
|
||||
"value": "This is a sample top-level community",
|
||||
"language": null
|
||||
},
|
||||
{
|
||||
"key": "dc.description.tableofcontents",
|
||||
"value": "<p>This is the <em>news section</em> for this <em>Sample Community</em>. System or Community Administrators (of this Community) can edit this News field.</p>",
|
||||
"language": null
|
||||
},
|
||||
{
|
||||
"key": "dc.rights",
|
||||
"value": "<p><em>If this Community had special copyright text to display, it would be displayed here.</em></p>",
|
||||
"language": null
|
||||
},
|
||||
{
|
||||
"key": "dc.title",
|
||||
"value": "Sample Community",
|
||||
"language": null
|
||||
}
|
||||
],
|
||||
"_links": {
|
||||
"self": {
|
||||
"href": "http://dspace7.4science.it/dspace-spring-rest/api/core/community/9076bd16-e69a-48d6-9e41-0238cb40d863"
|
||||
},
|
||||
"collections": [
|
||||
{ "href": "/collections/5179" }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Community 2",
|
||||
"handle": "10673/2",
|
||||
"id": "2365",
|
||||
"uuid": "80eec4c6-70bd-4beb-b3d4-5d46c6343157",
|
||||
"type": "community",
|
||||
"metadata": [
|
||||
{
|
||||
"key": "dc.description",
|
||||
"value": "<p>This is the introductory text for the <em>Sample Community</em> on the DSpace Demonstration Site. It is editable by System or Community Administrators (of this Community).</p>\r\n<p><strong>DSpace Communities may contain one or more Sub-Communities or Collections (of Items).</strong></p>\r\n<p>This particular Community has its own logo (the <a href=\"http://www.duraspace.org/\">DuraSpace</a> logo).</p>",
|
||||
"language": null
|
||||
},
|
||||
{
|
||||
"key": "dc.description.abstract",
|
||||
"value": "This is a sample top-level community",
|
||||
"language": null
|
||||
},
|
||||
{
|
||||
"key": "dc.description.tableofcontents",
|
||||
"value": "<p>This is the <em>news section</em> for this <em>Sample Community</em>. System or Community Administrators (of this Community) can edit this News field.</p>",
|
||||
"language": null
|
||||
},
|
||||
{
|
||||
"key": "dc.rights",
|
||||
"value": "<p><em>If this Community had special copyright text to display, it would be displayed here.</em></p>",
|
||||
"language": null
|
||||
},
|
||||
{
|
||||
"key": "dc.title",
|
||||
"value": "Sample Community",
|
||||
"language": null
|
||||
}
|
||||
],
|
||||
"_links": {
|
||||
"self": {
|
||||
"href": "http://dspace7.4science.it/dspace-spring-rest/api/core/community/9076bd16-e69a-48d6-9e41-0238cb40d863"
|
||||
},
|
||||
"collections": [
|
||||
{ "href": "/collections/6547" }
|
||||
]
|
||||
}
|
||||
}
|
||||
];
|
Reference in New Issue
Block a user