3 class Notes < Grape::API
4 before { authenticate! }
6 NOTEABLE_TYPES = [Issue, MergeRequest, Snippet]
9 # Get a list of project wall notes
12 # id (required) - The ID of a project
14 # GET /projects/:id/notes
16 @notes = user_project.notes.common
18 # Get recent notes if recent = true
19 @notes = @notes.order('id DESC') if params[:recent]
21 present paginate(@notes), with: Entities::Note
24 # Get a single project wall note
27 # id (required) - The ID of a project
28 # note_id (required) - The ID of a note
30 # GET /projects/:id/notes/:note_id
31 get ":id/notes/:note_id" do
32 @note = user_project.notes.common.find(params[:note_id])
33 present @note, with: Entities::Note
36 # Create a new project wall note
39 # id (required) - The ID of a project
40 # body (required) - The content of a note
42 # POST /projects/:id/notes
44 required_attributes! [:body]
46 @note = user_project.notes.new(note: params[:body])
47 @note.author = current_user
50 present @note, with: Entities::Note
52 # :note is exposed as :body, but :note is set on error
53 bad_request!(:note) if @note.errors[:note].any?
58 NOTEABLE_TYPES.each do |noteable_type|
59 noteables_str = noteable_type.to_s.underscore.pluralize
60 noteable_id_str = "#{noteable_type.to_s.underscore}_id"
62 # Get a list of project +noteable+ notes
65 # id (required) - The ID of a project
66 # noteable_id (required) - The ID of an issue or snippet
68 # GET /projects/:id/issues/:noteable_id/notes
69 # GET /projects/:id/snippets/:noteable_id/notes
70 get ":id/#{noteables_str}/:#{noteable_id_str}/notes" do
71 @noteable = user_project.send(:"#{noteables_str}").find(params[:"#{noteable_id_str}"])
72 present paginate(@noteable.notes), with: Entities::Note
75 # Get a single +noteable+ note
78 # id (required) - The ID of a project
79 # noteable_id (required) - The ID of an issue or snippet
80 # note_id (required) - The ID of a note
82 # GET /projects/:id/issues/:noteable_id/notes/:note_id
83 # GET /projects/:id/snippets/:noteable_id/notes/:note_id
84 get ":id/#{noteables_str}/:#{noteable_id_str}/notes/:note_id" do
85 @noteable = user_project.send(:"#{noteables_str}").find(params[:"#{noteable_id_str}"])
86 @note = @noteable.notes.find(params[:note_id])
87 present @note, with: Entities::Note
90 # Create a new +noteable+ note
93 # id (required) - The ID of a project
94 # noteable_id (required) - The ID of an issue or snippet
95 # body (required) - The content of a note
97 # POST /projects/:id/issues/:noteable_id/notes
98 # POST /projects/:id/snippets/:noteable_id/notes
99 post ":id/#{noteables_str}/:#{noteable_id_str}/notes" do
100 required_attributes! [:body]
102 @noteable = user_project.send(:"#{noteables_str}").find(params[:"#{noteable_id_str}"])
103 @note = @noteable.notes.new(note: params[:body])
104 @note.author = current_user
105 @note.project = user_project
108 present @note, with: Entities::Note