2016-06-17 20:25:44 +02:00
|
|
|
'use strict';
|
|
|
|
|
2016-06-19 19:16:40 +02:00
|
|
|
const api = require('../api.js');
|
|
|
|
const AbstractList = require('./abstract_list.js');
|
2016-06-17 20:25:44 +02:00
|
|
|
const Post = require('./post.js');
|
|
|
|
|
2016-06-19 19:16:40 +02:00
|
|
|
class PostList extends AbstractList {
|
|
|
|
static getAround(id, searchQuery) {
|
2016-09-04 01:25:19 +02:00
|
|
|
const url =
|
|
|
|
`/post/${id}/around?fields=id` +
|
|
|
|
`&query=${encodeURIComponent(searchQuery)}`;
|
2017-01-08 02:12:38 +01:00
|
|
|
return api.get(url);
|
2016-06-17 20:25:44 +02:00
|
|
|
}
|
|
|
|
|
2016-06-19 19:16:40 +02:00
|
|
|
static search(text, page, pageSize, fields) {
|
|
|
|
const url =
|
2016-09-04 01:25:19 +02:00
|
|
|
`/posts/?query=${encodeURIComponent(text)}` +
|
2016-06-19 19:16:40 +02:00
|
|
|
`&page=${page}` +
|
|
|
|
`&pageSize=${pageSize}` +
|
|
|
|
`&fields=${fields.join(',')}`;
|
|
|
|
return api.get(url).then(response => {
|
|
|
|
return Promise.resolve(Object.assign(
|
|
|
|
{},
|
|
|
|
response,
|
|
|
|
{results: PostList.fromResponse(response.results)}));
|
|
|
|
});
|
2016-06-17 20:25:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-19 19:16:40 +02:00
|
|
|
PostList._itemClass = Post;
|
|
|
|
PostList._itemName = 'post';
|
|
|
|
|
2016-06-17 20:25:44 +02:00
|
|
|
module.exports = PostList;
|