diff --git a/framework/core/ember/app/adapters/application.js b/framework/core/ember/app/adapters/application.js index da2a2d7d4..ec39c711d 100644 --- a/framework/core/ember/app/adapters/application.js +++ b/framework/core/ember/app/adapters/application.js @@ -1,37 +1,8 @@ import JsonApiAdapter from 'ember-json-api/json-api-adapter'; + export default JsonApiAdapter.extend({ - host: '/api', - findQuery: function(store, type, query) { - var ids = null; - if (query.ids) { - ids = query.ids.join(','); - delete query.ids; - } - return this.ajax(this.buildURL(type.typeKey, ids), 'GET', {data: query}); - }, -}); - -// export default DS.JsonApiAdapter.extend({ -// host: '/api', - -// // xhr: [], - -// // ajax: function(url, type, hash) { -// // var adapter = this; - -// // return new Ember.RSVP.Promise(function(resolve, reject) { -// // hash = adapter.ajaxOptions(url, type, hash); - -// // hash.success = function(json) { -// // Ember.run(null, resolve, json); -// // }; - -// // hash.error = function(jqXHR, textStatus, errorThrown) { -// // Ember.run(null, reject, adapter.ajaxError(jqXHR)); -// // }; - -// // adapter.xhr.push(Ember.$.ajax(hash)); -// // }, "DS: RestAdapter#ajax " + type + " to " + url); -// // }, -// }); + // Todo: make this loaded via an environment variable or something + host: '/api' + +}); \ No newline at end of file diff --git a/framework/core/ember/app/serializers/application.js b/framework/core/ember/app/serializers/application.js index 31200acf3..62de25084 100644 --- a/framework/core/ember/app/serializers/application.js +++ b/framework/core/ember/app/serializers/application.js @@ -1,4 +1,5 @@ import JsonApiSerializer from 'ember-json-api/json-api-serializer'; + export default JsonApiSerializer.extend({ normalize: function(type, hash, property) { var json = {}; diff --git a/framework/core/src/Flarum/Api/Actions/Posts/Index.php b/framework/core/src/Flarum/Api/Actions/Posts/Index.php index 6b53b0f23..862e71dbb 100644 --- a/framework/core/src/Flarum/Api/Actions/Posts/Index.php +++ b/framework/core/src/Flarum/Api/Actions/Posts/Index.php @@ -8,13 +8,14 @@ use Flarum\Api\Serializers\PostSerializer; class Index extends Base { /** - * Show posts from a discussion. + * Show posts from a discussion, or by providing an array of IDs. * * @return Response */ protected function run() { $discussionId = $this->input('discussions'); + $postIds = (array) $this->input('ids'); $count = $this->count(20, 50); @@ -40,9 +41,16 @@ class Index extends Base // @todo move to post repository $posts = Post::with($relations) - ->whereCanView() - ->where('discussion_id', $discussionId) - ->skip($start) + ->whereCanView(); + + if ($discussionId) { + $posts->where('discussion_id', $discussionId); + } + if (count($postIds)) { + $posts->whereIn('id', $postIds); + } + + $posts = $posts->skip($start) ->take($count) ->orderBy($sort['by'], $sort['order'] ?: 'asc') ->get();