Commit 1c5aa848ce6141b8679e167171096055dc7f4df3
1 parent
9a4974b7
Exists in
master
and in
4 other branches
API: get a single note
Showing
2 changed files
with
35 additions
and
2 deletions
Show diff stats
lib/api/notes.rb
| ... | ... | @@ -33,6 +33,21 @@ module Gitlab |
| 33 | 33 | @noteable = user_project.send(:"#{noteables_str}").find(params[:"#{noteable_id_str}"]) |
| 34 | 34 | present paginate(@noteable.notes), with: Entities::Note |
| 35 | 35 | end |
| 36 | + | |
| 37 | + # Get a single +noteable+ note | |
| 38 | + # | |
| 39 | + # Parameters: | |
| 40 | + # id (required) - The ID or code name of a project | |
| 41 | + # noteable_id (required) - The ID of an issue or snippet | |
| 42 | + # note_id (required) - The ID of a note | |
| 43 | + # Example Request: | |
| 44 | + # GET /projects/:id/issues/:noteable_id/notes/:note_id | |
| 45 | + # GET /projects/:id/snippets/:noteable_id/notes/:note_id | |
| 46 | + get ":id/#{noteables_str}/:#{noteable_id_str}/notes/:note_id" do | |
| 47 | + @noteable = user_project.send(:"#{noteables_str}").find(params[:"#{noteable_id_str}"]) | |
| 48 | + @note = @noteable.notes.find(params[:note_id]) | |
| 49 | + present @note, with: Entities::Note | |
| 50 | + end | |
| 36 | 51 | end |
| 37 | 52 | end |
| 38 | 53 | end | ... | ... |
spec/requests/api/notes_spec.rb
| ... | ... | @@ -32,7 +32,7 @@ describe Gitlab::API do |
| 32 | 32 | |
| 33 | 33 | describe "GET /projects/:id/noteable/:noteable_id/notes" do |
| 34 | 34 | context "when noteable is an Issue" do |
| 35 | - it "should return an array of notes" do | |
| 35 | + it "should return an array of issue notes" do | |
| 36 | 36 | get api("/projects/#{project.id}/issues/#{issue.id}/notes", user) |
| 37 | 37 | response.status.should == 200 |
| 38 | 38 | json_response.should be_an Array |
| ... | ... | @@ -41,7 +41,7 @@ describe Gitlab::API do |
| 41 | 41 | end |
| 42 | 42 | |
| 43 | 43 | context "when noteable is a Snippet" do |
| 44 | - it "should return an array of notes" do | |
| 44 | + it "should return an array of snippet notes" do | |
| 45 | 45 | get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user) |
| 46 | 46 | response.status.should == 200 |
| 47 | 47 | json_response.should be_an Array |
| ... | ... | @@ -49,4 +49,22 @@ describe Gitlab::API do |
| 49 | 49 | end |
| 50 | 50 | end |
| 51 | 51 | end |
| 52 | + | |
| 53 | + describe "GET /projects/:id/noteable/:noteable_id/notes/:note_id" do | |
| 54 | + context "when noteable is an Issue" do | |
| 55 | + it "should return an issue note by id" do | |
| 56 | + get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{issue_note.id}", user) | |
| 57 | + response.status.should == 200 | |
| 58 | + json_response['body'].should == issue_note.note | |
| 59 | + end | |
| 60 | + end | |
| 61 | + | |
| 62 | + context "when noteable is a Snippet" do | |
| 63 | + it "should return a snippet note by id" do | |
| 64 | + get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/#{snippet_note.id}", user) | |
| 65 | + response.status.should == 200 | |
| 66 | + json_response['body'].should == snippet_note.note | |
| 67 | + end | |
| 68 | + end | |
| 69 | + end | |
| 52 | 70 | end | ... | ... |