From 6b0e2b2a714709ce23e600207b96578d84e82baa Mon Sep 17 00:00:00 2001 From: Connor Shea Date: Fri, 13 Jan 2017 18:27:37 -0500 Subject: Add more to the Note Templates API. --- lib/api/entities.rb | 6 ++++ lib/api/note_templates.rb | 62 +++++++++++++++++++++++++++++--- spec/requests/api/note_templates_spec.rb | 20 +++++++++++ 3 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 spec/requests/api/note_templates_spec.rb 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 -- cgit v1.2.1