@@ -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" }
0 commit comments