Skip to content

Commit e2b50ee

Browse files
author
Alex Tharp
authored
Merge pull request #511 from cbdr/bugfix/AR-66-Broken-Pagination-Headers
AR-66: Broken Pagination Headers
2 parents 7b2f3b1 + 254713d commit e2b50ee

File tree

11 files changed

+28
-42
lines changed

11 files changed

+28
-42
lines changed

Gemfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ gem 'cortex-exceptions', '= 0.0.4'
1515
gem 'cortex-plugins-core', '= 0.12.4'
1616

1717
# API
18-
gem 'grape', '~> 0.17'
19-
gem 'grape-entity', '~> 0.6.0'
20-
gem 'grape-swagger', '~> 0.27.1'
18+
gem 'grape', '~> 0.19.2'
19+
gem 'grape-entity', '~> 0.6.1'
20+
gem 'grape-swagger', '~> 0.27.2'
2121

2222
# Authorization
2323
gem 'six', '~> 0.2.0'
@@ -36,7 +36,7 @@ gem 'image_optim_pack', '~> 0.4.0'
3636
gem 'acts-as-taggable-on', '~> 4.0'
3737
gem 'bcrypt', '~> 3.1.11'
3838
gem 'kaminari', '~> 0.17.0'
39-
gem 'grape-kaminari', git: 'https://github.com/toastercup/grape-kaminari.git', branch: 'set-paginate-headers-extraction'
39+
gem 'grape-kaminari', '~> 0.1.9'
4040
gem 'elasticsearch-model', '~> 5.0'
4141
gem 'elasticsearch-rails', '~> 5.0'
4242
gem 'paranoia', '~> 2.3'

Gemfile.lock

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@ GIT
55
awesome_nested_set (3.1.2)
66
activerecord (>= 4.0.0, < 5.1)
77

8-
GIT
9-
remote: https://github.com/toastercup/grape-kaminari.git
10-
revision: 661388050eaa97f70006b74fe300e19760b8a132
11-
branch: set-paginate-headers-extraction
12-
specs:
13-
grape-kaminari (0.1.9)
14-
grape
15-
kaminari
16-
178
GIT
189
remote: https://github.com/triloch/rails-observers.git
1910
revision: ea30390cb07b4a37dd2f9d03966c89c1372f9dbe
@@ -251,7 +242,10 @@ GEM
251242
grape-entity (0.6.1)
252243
activesupport (>= 5.0.0)
253244
multi_json (>= 1.3.2)
254-
grape-swagger (0.27.1)
245+
grape-kaminari (0.1.9)
246+
grape
247+
kaminari
248+
grape-swagger (0.27.2)
255249
grape (>= 0.16.2)
256250
guard (2.14.1)
257251
formatador (>= 0.2.4)
@@ -640,10 +634,10 @@ DEPENDENCIES
640634
font-awesome-sass (~> 4.7.0)
641635
foreman
642636
gon (~> 6.1.0)
643-
grape (~> 0.17)
644-
grape-entity (~> 0.6.0)
645-
grape-kaminari!
646-
grape-swagger (~> 0.27.1)
637+
grape (~> 0.19.2)
638+
grape-entity (~> 0.6.1)
639+
grape-kaminari (~> 0.1.9)
640+
grape-swagger (~> 0.27.2)
647641
guard-jasmine (~> 2.1)
648642
guard-rspec (~> 4.7)
649643
haml (~> 5.0)

app/api/v1/resources/media.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ class Media < Grape::API
2020
require_scope! 'view:media'
2121

2222
@media = ::GetMultipleMedia.call(params: declared(clean_params(params), include_missing: false), tenant: current_tenant).media
23-
set_paginate_headers(@media)
24-
::V1::Entities::Media.represent @media.to_a
23+
::V1::Entities::Media.represent paginate(@media).records
2524
end
2625

2726
desc 'Show media tags'

app/api/v1/resources/posts.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ class Posts < Grape::API
2020
require_scope! 'view:posts'
2121
authorize! :view, ::Post
2222
@posts = ::GetPosts.call(params: declared(clean_params(params), include_missing: false), tenant: current_tenant).posts
23-
set_paginate_headers(@posts)
24-
::V1::Entities::Post.represent @posts.to_a
23+
::V1::Entities::Post.represent paginate(@posts).records
2524
end
2625

2726
desc 'Show published posts', { entity: ::V1::Entities::Post, nickname: "postFeed" }
@@ -37,13 +36,14 @@ class Posts < Grape::API
3736
params_hash = Digest::MD5.hexdigest(declared(params).to_s)
3837
cache_key = "feed-#{last_updated_at}-#{current_tenant.id}-#{params_hash}"
3938

40-
posts_page = ::Rails.cache.fetch(cache_key, expires_in: 30.minutes, race_condition_ttl: 10) do
39+
posts = ::Rails.cache.fetch(cache_key, expires_in: 30.minutes, race_condition_ttl: 10) do
4140
posts = ::GetPosts.call(params: declared(clean_params(params), include_missing: false), tenant: current_tenant, published: true).posts
42-
set_paginate_headers(posts)
43-
::V1::Entities::Post.represent posts.to_a
41+
paginated_posts = paginate(posts).records.to_a
42+
{records: paginated_posts, headers: header}
4443
end
4544

46-
posts_page
45+
header.merge!(posts[:headers])
46+
::V1::Entities::Post.represent posts[:records]
4747
end
4848

4949
desc 'Show all published posts', { entity: ::V1::Entities::Post, nickname: "allPostFeed" }
@@ -53,7 +53,7 @@ class Posts < Grape::API
5353
authorize! :view, ::Post
5454

5555
posts = ::GetPosts.call(params: declared(clean_params(params), include_missing: false), tenant: current_tenant, published: true).posts
56-
posts_page = ::V1::Entities::Post.represent posts.to_a
56+
::V1::Entities::Post.represent paginate(posts).records
5757
end
5858

5959
desc 'Show published post authors'
@@ -70,8 +70,7 @@ class Posts < Grape::API
7070
authorize! :view, post
7171

7272
@posts = ::GetRelatedPosts.call(post: post, params: declared(clean_params(params), include_missing: false), tenant: current_tenant, published: true).posts
73-
set_paginate_headers(@posts)
74-
::V1::Entities::Post.represent @posts.to_a
73+
::V1::Entities::Post.represent paginate(@posts).records
7574
end
7675

7776
desc 'Show a published post', { entity: ::V1::Entities::Post, nickname: "showFeedPost" }

app/api/v1/resources/tenants.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ class Tenants < Grape::API
8282
require_scope! 'view:users'
8383

8484
@users = ::GetUsers.call(params: declared(clean_params(params), include_missing: false), tenant_id: params[:id]).users
85-
set_paginate_headers(@users)
86-
::V1::Entities::User.represent @users, full: true
85+
::V1::Entities::User.represent paginate(@users).records, full: true
8786
end
8887
end
8988
end

app/api/v1/resources/webpages.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ class Webpages < Grape::API
1717
require_scope! 'view:webpages'
1818

1919
@webpages = ::GetWebpages.call(params: declared(clean_params(params), include_missing: false), tenant: current_tenant).webpages
20-
set_paginate_headers(@webpages)
21-
::V1::Entities::Webpage.represent @webpages.to_a, full: true
20+
::V1::Entities::Webpage.represent paginate(@webpages).records, full: true
2221
end
2322

2423
desc 'Show Webpage Snippets as public feed by URL', { entity: ::V1::Entities::Webpage, nickname: 'showWebpageFeed' }

app/interactors/get_multiple_media.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ def call
1212
media = media.show_all(context.tenant)
1313
end
1414

15-
media = media.page(context.params.page).per(context.params.per_page)
16-
context.media = media.records
15+
context.media = media
1716
end
1817

1918
private

app/interactors/get_posts.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ def call
1212
posts = posts.show_all(context.tenant, context.published)
1313
end
1414

15-
posts = posts.page(context.params.page).per(context.params.per_page)
16-
context.posts = posts.records
15+
context.posts = posts
1716
end
1817

1918
private

app/interactors/get_related_posts.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ class GetRelatedPosts
44
def call
55
related = context.post.related(context.tenant, context.published)
66

7-
context.posts = related.page(context.params.page).per(context.params.per_page).records
7+
context.posts = related
88
end
99
end

app/interactors/get_users.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ def call
1212
users = users.show_all(context.tenant_id)
1313
end
1414

15-
users = users.page(context.params.page).per(context.params.per_page)
16-
context.users = users.records
15+
context.users = users
1716
end
1817

1918
private

0 commit comments

Comments
 (0)