diff options
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/entities.rb | 6 | ||||
-rw-r--r-- | lib/api/note_templates.rb | 62 |
2 files changed, 63 insertions, 5 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 885ce7d44bc..0cc0db62138 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -337,6 +337,12 @@ module API expose(:downvote?) { |note| false } end + class NoteTemplate < Grape::Entity + expose :id + expose :title + expose :note + end + class AwardEmoji < Grape::Entity expose :id expose :name diff --git a/lib/api/note_templates.rb b/lib/api/note_templates.rb index f4ae76e7791..720b3e2013c 100644 --- a/lib/api/note_templates.rb +++ b/lib/api/note_templates.rb @@ -1,16 +1,68 @@ module API class NoteTemplates < Grape::API + include PaginationParams + before { authenticate! } - resource :note_templates - desc 'Get global notification level settings and email, defaults to Participate' do - success Entities::NoteTemplates + resource :note_templates do + desc 'Get all note templates for the authenticated user' do + success Entities::NoteTemplate end get do - + NoteTemplate.all + end + + desc 'Get a note templates for the authenticated user' do + success Entities::NoteTemplate + end + params do + requires :id, type: Integer, desc: "The ID of the note template." + end + get "note_templates/:id" do + note_template = NoteTemplate.find_by(id: params[:id]) + + present note_template, with: Entities::NoteTemplate + end + + desc 'Create a note template for the authenticated user' do + success Entities::NoteTemplate + end + params do + requires :title, type: String, desc: "The title of the note template." + requires :note, type: String, desc: "The body of the note template." end - put do + post do + note_template = NoteTemplate.create!(declared(params, include_parent_namespaces: false).to_h) + + present note_template, with: Entities::NoteTemplate, current_user: current_user + end + + desc 'Update a note template for the authenticated user' do + success Entities::NoteTemplate + end + params do + requires :id, type: Integer, desc: "The ID of the note template." + optional :title, type: String, desc: "The title of the note template." + optional :note, type: String, desc: "The body of the note template." + at_least_one_of :title, :note + end + put "note_templates/:id" do + note_template = NoteTemplate.find(params[:id]) + note_template.update_attributes(declared(params, include_parent_namespaces: false).to_h) + + present note_template, with: Entities::NoteTemplate + end + + desc 'Delete a note template for the authenticated user' do + success Entities::NoteTemplate + end + params do + requires :id, type: Integer, desc: "The ID of the note template." + end + delete "note_templates/:id" do + puts 'test' end + end end end |