diff options
author | Connor Shea <connor.james.shea@gmail.com> | 2017-01-13 18:27:37 -0500 |
---|---|---|
committer | Connor Shea <connor.james.shea@gmail.com> | 2017-01-13 18:58:35 -0500 |
commit | 6b0e2b2a714709ce23e600207b96578d84e82baa (patch) | |
tree | 9e5f57d0be38164c91ea00cdea5b3ff77113bcc1 | |
parent | 47cc91b4555e8fc1a588152d33e4ffd2a3e8fc2d (diff) | |
download | gitlab-ce-cs-note-templates.tar.gz |
Add more to the Note Templates API.cs-note-templates
-rw-r--r-- | lib/api/entities.rb | 6 | ||||
-rw-r--r-- | lib/api/note_templates.rb | 62 | ||||
-rw-r--r-- | spec/requests/api/note_templates_spec.rb | 20 |
3 files changed, 83 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 diff --git a/spec/requests/api/note_templates_spec.rb b/spec/requests/api/note_templates_spec.rb new file mode 100644 index 00000000000..37b6ccb5b3d --- /dev/null +++ b/spec/requests/api/note_templates_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe API::Notes, api: true do + include ApiHelpers + + let(:user) { create(:user) } + let(:note_template) { create(:note_template) } + + describe "GET /note_templates" do + + end + + describe "PUT /note_templates" do + + end + + describe "DELETE /note_templates/ :id" do + + end +end |