Commit a8e4e8b9413314bff239597b313a1f8c592c5654
1 parent
7c83fd47
Exists in
web_steps_improvements
and in
6 other branches
comment_paragraph: return count for paragraphs in api
Showing
2 changed files
with
18 additions
and
0 deletions
Show diff stats
plugins/comment_paragraph/lib/comment_paragraph_plugin/api.rb
@@ -21,5 +21,11 @@ class CommentParagraphPlugin::API < Grape::API | @@ -21,5 +21,11 @@ class CommentParagraphPlugin::API < Grape::API | ||
21 | present_partial article, :with => Noosfero::API::Entities::Article | 21 | present_partial article, :with => Noosfero::API::Entities::Article |
22 | end | 22 | end |
23 | end | 23 | end |
24 | + | ||
25 | + get ':id/comment_paragraph_plugin/comments/count' do | ||
26 | + article = find_article(environment.articles, params[:id]) | ||
27 | + comments = select_filtered_collection_of(article, :comments, params) | ||
28 | + comments.group(:paragraph_uuid).count | ||
29 | + end | ||
24 | end | 30 | end |
25 | end | 31 | end |
plugins/comment_paragraph/test/unit/api_test.rb
@@ -56,4 +56,16 @@ class APITest < ActiveSupport::TestCase | @@ -56,4 +56,16 @@ class APITest < ActiveSupport::TestCase | ||
56 | assert_equal 403, last_response.status | 56 | assert_equal 403, last_response.status |
57 | end | 57 | end |
58 | end | 58 | end |
59 | + | ||
60 | + should 'return comment counts grouped by paragraph' do | ||
61 | + article = fast_create(TextArticle, :profile_id => person.id, :name => "Some thing", :published => false) | ||
62 | + fast_create(Comment, :paragraph_uuid => '1', :source_id => article.id) | ||
63 | + fast_create(Comment, :paragraph_uuid => nil, :source_id => article.id) | ||
64 | + fast_create(Comment, :paragraph_uuid => '2', :source_id => article.id) | ||
65 | + fast_create(Comment, :paragraph_uuid => '2', :source_id => article.id) | ||
66 | + get "/api/v1/articles/#{article.id}/comment_paragraph_plugin/comments/count?#{params.to_query}" | ||
67 | + | ||
68 | + json = JSON.parse(last_response.body) | ||
69 | + assert_equal({"1"=>1, ""=>1, "2"=>2}, json) | ||
70 | + end | ||
59 | end | 71 | end |