From 2fd3f5d97a0c8a38d9d09f8bc09517bd93728dd0 Mon Sep 17 00:00:00 2001 From: Alex Legler Date: Mon, 27 Aug 2012 22:25:11 +0200 Subject: API: Setup and first function: Create request --- app/controllers/api/glsa_controller.rb | 22 ++++++++++++++++++++++ app/helpers/api/glsa_helper.rb | 2 ++ app/views/api/glsa/create_request.html.erb | 2 ++ config/routes.rb | 2 ++ test/functional/api/glsa_controller_test.rb | 9 +++++++++ test/unit/helpers/api/glsa_helper_test.rb | 4 ++++ 6 files changed, 41 insertions(+) create mode 100644 app/controllers/api/glsa_controller.rb create mode 100644 app/helpers/api/glsa_helper.rb create mode 100644 app/views/api/glsa/create_request.html.erb create mode 100644 test/functional/api/glsa_controller_test.rb create mode 100644 test/unit/helpers/api/glsa_helper_test.rb diff --git a/app/controllers/api/glsa_controller.rb b/app/controllers/api/glsa_controller.rb new file mode 100644 index 0000000..7645dfd --- /dev/null +++ b/app/controllers/api/glsa_controller.rb @@ -0,0 +1,22 @@ +class Api::GlsaController < ApplicationController + layout false + + # Limited to creating requests for now + def create + @glsa = nil + + if params[:type] == 'request' + @glsa = Glsa.new_request(params[:title], params[:bugs], params[:comment], params[:access], (params[:import_references].to_i == 1), current_user) + Glsamaker::Mail.request_notification(@glsa, current_user) + end + + respond_to do |format| + if @glsa and @glsa.save + format.json { render :json => @glsa, :status => :created } + else + format.json { render :json => @glsa ? @glsa.errors : ['error: unknown action'], :status => :unprocessable_entity } + end + end + end + +end diff --git a/app/helpers/api/glsa_helper.rb b/app/helpers/api/glsa_helper.rb new file mode 100644 index 0000000..22f2ceb --- /dev/null +++ b/app/helpers/api/glsa_helper.rb @@ -0,0 +1,2 @@ +module Api::GlsaHelper +end diff --git a/app/views/api/glsa/create_request.html.erb b/app/views/api/glsa/create_request.html.erb new file mode 100644 index 0000000..7ac0448 --- /dev/null +++ b/app/views/api/glsa/create_request.html.erb @@ -0,0 +1,2 @@ +

Api::Glsa#create_request

+

Find me in app/views/api/glsa/create_request.html.erb

diff --git a/config/routes.rb b/config/routes.rb index 1b46f3e..ce16275 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,6 +9,8 @@ Glsamaker::Application.routes.draw do match 'admin' => 'admin/index#index' + match 'api/glsa/create_request' => 'api/glsa#create_request' + resources :glsas, :controller => 'glsa' do resources :comments resources :bugs diff --git a/test/functional/api/glsa_controller_test.rb b/test/functional/api/glsa_controller_test.rb new file mode 100644 index 0000000..d214f08 --- /dev/null +++ b/test/functional/api/glsa_controller_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class Api::GlsaControllerTest < ActionController::TestCase + test "should get create_request" do + get :create_request + assert_response :success + end + +end diff --git a/test/unit/helpers/api/glsa_helper_test.rb b/test/unit/helpers/api/glsa_helper_test.rb new file mode 100644 index 0000000..b651f0f --- /dev/null +++ b/test/unit/helpers/api/glsa_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class Api::GlsaHelperTest < ActionView::TestCase +end -- cgit v1.2.3-65-gdbad