Commit cf12763d5b6bacd073586ba10579618a60d7ca52
Exists in
master
and in
4 other branches
Merge pull request #2127 from NARKOZ/notes-api
API: don't expose 'updated_at' for notes
Showing
5 changed files
with
47 additions
and
6 deletions
Show diff stats
CHANGELOG
| 1 | 1 | v 3.2.0 |
| 2 | - - [API] create notes for snippets and issues | |
| 3 | - - [API] list notes for snippets and issues | |
| 4 | - - [API] list project wall notes | |
| 2 | + - [API] list, create issue notes | |
| 3 | + - [API] list, create snippet notes | |
| 4 | + - [API] list, create wall notes | |
| 5 | 5 | - Remove project code - use path instead |
| 6 | 6 | - added username field to user |
| 7 | 7 | - rake task to fill usernames based on emails create namespaces for users | ... | ... |
doc/api/notes.md
| ... | ... | @@ -20,8 +20,7 @@ GET /projects/:id/notes |
| 20 | 20 | "blocked": false, |
| 21 | 21 | "created_at": "2012-05-23T08:00:58Z" |
| 22 | 22 | }, |
| 23 | - "updated_at":"2012-11-27T19:16:44Z", | |
| 24 | - "created_at":"2012-11-27T19:16:44Z" | |
| 23 | + "created_at": "2012-11-27T19:16:44Z" | |
| 25 | 24 | } |
| 26 | 25 | ] |
| 27 | 26 | ``` |
| ... | ... | @@ -88,6 +87,22 @@ Parameters: |
| 88 | 87 | |
| 89 | 88 | ## New note |
| 90 | 89 | |
| 90 | +### New wall note | |
| 91 | + | |
| 92 | +Create a new wall note. | |
| 93 | + | |
| 94 | +``` | |
| 95 | +POST /projects/:id/notes | |
| 96 | +``` | |
| 97 | + | |
| 98 | +Parameters: | |
| 99 | + | |
| 100 | ++ `id` (required) - The ID or code name of a project | |
| 101 | ++ `body` (required) - The content of a note | |
| 102 | + | |
| 103 | +Will return created note with status `201 Created` on success, or `404 Not found` on fail. | |
| 104 | + | |
| 105 | + | |
| 91 | 106 | ### New issue note |
| 92 | 107 | |
| 93 | 108 | Create a new issue note. | ... | ... |
lib/api/entities.rb
lib/api/notes.rb
| ... | ... | @@ -17,6 +17,24 @@ module Gitlab |
| 17 | 17 | present paginate(@notes), with: Entities::Note |
| 18 | 18 | end |
| 19 | 19 | |
| 20 | + # Create a new project wall note | |
| 21 | + # | |
| 22 | + # Parameters: | |
| 23 | + # id (required) - The ID or code name of a project | |
| 24 | + # body (required) - The content of a note | |
| 25 | + # Example Request: | |
| 26 | + # POST /projects/:id/notes | |
| 27 | + post ":id/notes" do | |
| 28 | + @note = user_project.notes.new(note: params[:body]) | |
| 29 | + @note.author = current_user | |
| 30 | + | |
| 31 | + if @note.save | |
| 32 | + present @note, with: Entities::Note | |
| 33 | + else | |
| 34 | + not_found! | |
| 35 | + end | |
| 36 | + end | |
| 37 | + | |
| 20 | 38 | NOTEABLE_TYPES.each do |noteable_type| |
| 21 | 39 | noteables_str = noteable_type.to_s.underscore.pluralize |
| 22 | 40 | noteable_id_str = "#{noteable_type.to_s.underscore}_id" | ... | ... |
spec/requests/api/notes_spec.rb
| ... | ... | @@ -30,6 +30,14 @@ describe Gitlab::API do |
| 30 | 30 | end |
| 31 | 31 | end |
| 32 | 32 | |
| 33 | + describe "POST /projects/:id/notes" do | |
| 34 | + it "should create a new wall note" do | |
| 35 | + post api("/projects/#{project.id}/notes", user), body: 'hi!' | |
| 36 | + response.status.should == 201 | |
| 37 | + json_response['body'].should == 'hi!' | |
| 38 | + end | |
| 39 | + end | |
| 40 | + | |
| 33 | 41 | describe "GET /projects/:id/noteable/:noteable_id/notes" do |
| 34 | 42 | context "when noteable is an Issue" do |
| 35 | 43 | it "should return an array of issue notes" do | ... | ... |