From 2a5051376aac75c95cc57e3f39c3868cd5cf7c9f Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Tue, 21 Nov 2023 18:56:41 +0300 Subject: [PATCH] Add changeset comment search api json format --- .../_changeset_comment.json.jbuilder | 8 ++++++++ app/views/api/changeset_comments/index.json.jbuilder | 5 +++++ app/views/api/changesets/_changeset.json.jbuilder | 9 +-------- .../api/changeset_comments_controller_test.rb | 12 ++++++++++++ 4 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 app/views/api/changeset_comments/_changeset_comment.json.jbuilder create mode 100644 app/views/api/changeset_comments/index.json.jbuilder diff --git a/app/views/api/changeset_comments/_changeset_comment.json.jbuilder b/app/views/api/changeset_comments/_changeset_comment.json.jbuilder new file mode 100644 index 000000000..73b1ec908 --- /dev/null +++ b/app/views/api/changeset_comments/_changeset_comment.json.jbuilder @@ -0,0 +1,8 @@ +json.id changeset_comment.id +json.visible changeset_comment.visible +json.date changeset_comment.created_at.xmlschema +if changeset_comment.author.data_public? + json.uid changeset_comment.author.id + json.user changeset_comment.author.display_name +end +json.text changeset_comment.body diff --git a/app/views/api/changeset_comments/index.json.jbuilder b/app/views/api/changeset_comments/index.json.jbuilder new file mode 100644 index 000000000..0286b1a87 --- /dev/null +++ b/app/views/api/changeset_comments/index.json.jbuilder @@ -0,0 +1,5 @@ +json.partial! "api/root_attributes" + +json.comments(@comments) do |comment| + json.partial! comment +end diff --git a/app/views/api/changesets/_changeset.json.jbuilder b/app/views/api/changesets/_changeset.json.jbuilder index f0e461320..7001a95e8 100644 --- a/app/views/api/changesets/_changeset.json.jbuilder +++ b/app/views/api/changesets/_changeset.json.jbuilder @@ -23,13 +23,6 @@ json.tags changeset.tags unless changeset.tags.empty? if @comments json.comments(@comments) do |comment| - json.id comment.id - json.visible comment.visible - json.date comment.created_at.xmlschema - if comment.author.data_public? - json.uid comment.author.id - json.user comment.author.display_name - end - json.text comment.body + json.partial! comment end end diff --git a/test/controllers/api/changeset_comments_controller_test.rb b/test/controllers/api/changeset_comments_controller_test.rb index 2d8818986..ba4200d3f 100644 --- a/test/controllers/api/changeset_comments_controller_test.rb +++ b/test/controllers/api/changeset_comments_controller_test.rb @@ -9,6 +9,10 @@ module Api { :path => "/api/0.6/changeset_comments", :method => :get }, { :controller => "api/changeset_comments", :action => "index" } ) + assert_routing( + { :path => "/api/0.6/changeset_comments.json", :method => :get }, + { :controller => "api/changeset_comments", :action => "index", :format => "json" } + ) assert_routing( { :path => "/api/0.6/changeset/1/comment", :method => :post }, { :controller => "api/changeset_comments", :action => "create", :id => "1" } @@ -65,6 +69,14 @@ module Api get api_changeset_comments_path(:user => user1.id) assert_response :success assert_comments_in_order [comment22, comment21, comment11] + + get api_changeset_comments_path(:from => "2023-03-15T00:00:00Z", :format => "json") + assert_response :success + js = ActiveSupport::JSON.decode(@response.body) + assert_not_nil js + assert_equal 2, js["comments"].count + assert_equal comment23.id, js["comments"][0]["id"] + assert_equal comment22.id, js["comments"][1]["id"] end def test_create_by_unauthorized -- 2.39.5