diff --git a/Gemfile b/Gemfile index 8f9c1b977..19c345602 100644 --- a/Gemfile +++ b/Gemfile @@ -15,9 +15,9 @@ gem 'cortex-exceptions', '= 0.0.4' gem 'cortex-plugins-core', '= 0.12.4' # API -gem 'grape', '~> 0.17' -gem 'grape-entity', '~> 0.6.0' -gem 'grape-swagger', '~> 0.27.1' +gem 'grape', '~> 0.19.2' +gem 'grape-entity', '~> 0.6.1' +gem 'grape-swagger', '~> 0.27.2' # Authorization gem 'six', '~> 0.2.0' @@ -36,7 +36,7 @@ gem 'image_optim_pack', '~> 0.4.0' gem 'acts-as-taggable-on', '~> 4.0' gem 'bcrypt', '~> 3.1.11' gem 'kaminari', '~> 0.17.0' -gem 'grape-kaminari', git: 'https://github.com/toastercup/grape-kaminari.git', branch: 'set-paginate-headers-extraction' +gem 'grape-kaminari', '~> 0.1.9' gem 'elasticsearch-model', '~> 5.0' gem 'elasticsearch-rails', '~> 5.0' gem 'paranoia', '~> 2.3' diff --git a/Gemfile.lock b/Gemfile.lock index e8e0038d0..402ebf964 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,15 +5,6 @@ GIT awesome_nested_set (3.1.2) activerecord (>= 4.0.0, < 5.1) -GIT - remote: https://github.com/toastercup/grape-kaminari.git - revision: 661388050eaa97f70006b74fe300e19760b8a132 - branch: set-paginate-headers-extraction - specs: - grape-kaminari (0.1.9) - grape - kaminari - GIT remote: https://github.com/triloch/rails-observers.git revision: ea30390cb07b4a37dd2f9d03966c89c1372f9dbe @@ -251,7 +242,10 @@ GEM grape-entity (0.6.1) activesupport (>= 5.0.0) multi_json (>= 1.3.2) - grape-swagger (0.27.1) + grape-kaminari (0.1.9) + grape + kaminari + grape-swagger (0.27.2) grape (>= 0.16.2) guard (2.14.1) formatador (>= 0.2.4) @@ -640,10 +634,10 @@ DEPENDENCIES font-awesome-sass (~> 4.7.0) foreman gon (~> 6.1.0) - grape (~> 0.17) - grape-entity (~> 0.6.0) - grape-kaminari! - grape-swagger (~> 0.27.1) + grape (~> 0.19.2) + grape-entity (~> 0.6.1) + grape-kaminari (~> 0.1.9) + grape-swagger (~> 0.27.2) guard-jasmine (~> 2.1) guard-rspec (~> 4.7) haml (~> 5.0) diff --git a/app/api/v1/resources/media.rb b/app/api/v1/resources/media.rb index 469c4e14a..139bcc780 100644 --- a/app/api/v1/resources/media.rb +++ b/app/api/v1/resources/media.rb @@ -20,8 +20,7 @@ class Media < Grape::API require_scope! 'view:media' @media = ::GetMultipleMedia.call(params: declared(clean_params(params), include_missing: false), tenant: current_tenant).media - set_paginate_headers(@media) - ::V1::Entities::Media.represent @media.to_a + ::V1::Entities::Media.represent paginate(@media).records end desc 'Show media tags' diff --git a/app/api/v1/resources/posts.rb b/app/api/v1/resources/posts.rb index c57ad85a7..c2f9ef86a 100644 --- a/app/api/v1/resources/posts.rb +++ b/app/api/v1/resources/posts.rb @@ -20,8 +20,7 @@ class Posts < Grape::API require_scope! 'view:posts' authorize! :view, ::Post @posts = ::GetPosts.call(params: declared(clean_params(params), include_missing: false), tenant: current_tenant).posts - set_paginate_headers(@posts) - ::V1::Entities::Post.represent @posts.to_a + ::V1::Entities::Post.represent paginate(@posts).records end desc 'Show published posts', { entity: ::V1::Entities::Post, nickname: "postFeed" } @@ -37,13 +36,14 @@ class Posts < Grape::API params_hash = Digest::MD5.hexdigest(declared(params).to_s) cache_key = "feed-#{last_updated_at}-#{current_tenant.id}-#{params_hash}" - posts_page = ::Rails.cache.fetch(cache_key, expires_in: 30.minutes, race_condition_ttl: 10) do + posts = ::Rails.cache.fetch(cache_key, expires_in: 30.minutes, race_condition_ttl: 10) do posts = ::GetPosts.call(params: declared(clean_params(params), include_missing: false), tenant: current_tenant, published: true).posts - set_paginate_headers(posts) - ::V1::Entities::Post.represent posts.to_a + paginated_posts = paginate(posts).records.to_a + {records: paginated_posts, headers: header} end - posts_page + header.merge!(posts[:headers]) + ::V1::Entities::Post.represent posts[:records] end desc 'Show all published posts', { entity: ::V1::Entities::Post, nickname: "allPostFeed" } @@ -53,7 +53,7 @@ class Posts < Grape::API authorize! :view, ::Post posts = ::GetPosts.call(params: declared(clean_params(params), include_missing: false), tenant: current_tenant, published: true).posts - posts_page = ::V1::Entities::Post.represent posts.to_a + ::V1::Entities::Post.represent paginate(posts).records end desc 'Show published post authors' @@ -70,8 +70,7 @@ class Posts < Grape::API authorize! :view, post @posts = ::GetRelatedPosts.call(post: post, params: declared(clean_params(params), include_missing: false), tenant: current_tenant, published: true).posts - set_paginate_headers(@posts) - ::V1::Entities::Post.represent @posts.to_a + ::V1::Entities::Post.represent paginate(@posts).records end desc 'Show a published post', { entity: ::V1::Entities::Post, nickname: "showFeedPost" } diff --git a/app/api/v1/resources/tenants.rb b/app/api/v1/resources/tenants.rb index 34fafdd89..ed8df6699 100644 --- a/app/api/v1/resources/tenants.rb +++ b/app/api/v1/resources/tenants.rb @@ -82,8 +82,7 @@ class Tenants < Grape::API require_scope! 'view:users' @users = ::GetUsers.call(params: declared(clean_params(params), include_missing: false), tenant_id: params[:id]).users - set_paginate_headers(@users) - ::V1::Entities::User.represent @users, full: true + ::V1::Entities::User.represent paginate(@users).records, full: true end end end diff --git a/app/api/v1/resources/webpages.rb b/app/api/v1/resources/webpages.rb index 2ea36dca4..e59c1a996 100644 --- a/app/api/v1/resources/webpages.rb +++ b/app/api/v1/resources/webpages.rb @@ -17,8 +17,7 @@ class Webpages < Grape::API require_scope! 'view:webpages' @webpages = ::GetWebpages.call(params: declared(clean_params(params), include_missing: false), tenant: current_tenant).webpages - set_paginate_headers(@webpages) - ::V1::Entities::Webpage.represent @webpages.to_a, full: true + ::V1::Entities::Webpage.represent paginate(@webpages).records, full: true end desc 'Show Webpage Snippets as public feed by URL', { entity: ::V1::Entities::Webpage, nickname: 'showWebpageFeed' } diff --git a/app/interactors/get_multiple_media.rb b/app/interactors/get_multiple_media.rb index 6c87bb763..e5e74cb29 100644 --- a/app/interactors/get_multiple_media.rb +++ b/app/interactors/get_multiple_media.rb @@ -12,8 +12,7 @@ def call media = media.show_all(context.tenant) end - media = media.page(context.params.page).per(context.params.per_page) - context.media = media.records + context.media = media end private diff --git a/app/interactors/get_posts.rb b/app/interactors/get_posts.rb index 745fcd26c..f356202f1 100644 --- a/app/interactors/get_posts.rb +++ b/app/interactors/get_posts.rb @@ -12,8 +12,7 @@ def call posts = posts.show_all(context.tenant, context.published) end - posts = posts.page(context.params.page).per(context.params.per_page) - context.posts = posts.records + context.posts = posts end private diff --git a/app/interactors/get_related_posts.rb b/app/interactors/get_related_posts.rb index f053a4461..60fda0e7b 100644 --- a/app/interactors/get_related_posts.rb +++ b/app/interactors/get_related_posts.rb @@ -4,6 +4,6 @@ class GetRelatedPosts def call related = context.post.related(context.tenant, context.published) - context.posts = related.page(context.params.page).per(context.params.per_page).records + context.posts = related end end diff --git a/app/interactors/get_users.rb b/app/interactors/get_users.rb index d78f73c8f..409901a9d 100644 --- a/app/interactors/get_users.rb +++ b/app/interactors/get_users.rb @@ -12,8 +12,7 @@ def call users = users.show_all(context.tenant_id) end - users = users.page(context.params.page).per(context.params.per_page) - context.users = users.records + context.users = users end private diff --git a/app/interactors/get_webpages.rb b/app/interactors/get_webpages.rb index 566bbabc9..78fe8f9c8 100644 --- a/app/interactors/get_webpages.rb +++ b/app/interactors/get_webpages.rb @@ -12,8 +12,7 @@ def call webpages = webpages.show_all(context.tenant) end - webpages = webpages.page(context.params.page).per(context.params.per_page) - context.webpages = webpages.records + context.webpages = webpages end private