import request from 'request-promise';
import dispatcher from 'definity-dispatcher';
class CommentsRepository {
save(commentsId, comment) {
var uri = 'http://localhost:8080/api/comment-groups/' + commentsId + '/comments';
var method = 'POST';
if (comment._id) {
uri = uri + '/' + comment._id;
method = 'PUT';
}
var option = {uri:uri, method: method, body: comment, json: true, headers: {
'Content-Type': 'application/json; charset=utf-8'}
};
request(option);
}
remove(commentsId, id) {
var uri = 'http://localhost:8080/api/comment-groups/' + commentsId + '/comments/' + id;
request({uri:uri, method: 'DELETE'}).then((response) => {});
}
load(commentsId, skip = 0, limit = 5) {
this._load(commentsId, skip, limit).then((response) => {
dispatcher.dispatch('COMMENTS', response);
});
}
loadComments(commentsId, skip = 0, limit = 5) {
this._load(commentsId, skip, limit).then((response) => {
dispatcher.dispatch('LOAD_COMMENTS', response);
});
}
_load(commentsId, skip = 0, limit = 5) {
return request({uri:'http://localhost:8080/api/comment-groups/' + commentsId + '?skip=' + skip + '&limit=' + limit + '&sort=desc', json: true});
}
}
const commentsRepository = new CommentsRepository();
export default commentsRepository;
|