diff --git a/app/controllers/api/v1/product_build_lists_controller.rb b/app/controllers/api/v1/product_build_lists_controller.rb new file mode 100644 index 000000000..d8e1ec71f --- /dev/null +++ b/app/controllers/api/v1/product_build_lists_controller.rb @@ -0,0 +1,41 @@ +# -*- encoding : utf-8 -*- +class Api::V1::ProductBuildListsController < Api::V1::BaseController + before_filter :authenticate_user! + skip_before_filter :authenticate_user!, :only => [:index, :show] if APP_CONFIG['anonymous_access'] + + load_and_authorize_resource :product, :only => :index + load_and_authorize_resource :product_build_list + + def index + @product_build_lists = if @product + @product.product_build_lists + else + ProductBuildList.accessible_by current_ability, :read + end + @product_build_lists = @product_build_lists.joins(:product, :project, :arch) + @product_build_lists = @product_build_lists.recent.paginate(paginate_params) + end + + def create + create_subject @product_build_list + end + + def update + update_subject @product_build_list + end + + def show + end + + def destroy + destroy_subject @product_build_list + end + + def cancel + if @product_build_list.try(:can_cancel?) && @product_build_list.cancel + render_json_response @product_build_list, t("layout.product_build_lists.cancel_success") + else + render_validation_error @product_build_list, t("layout.product_build_lists.cancel_fail") + end + end +end diff --git a/app/views/api/v1/product_build_lists/_product_build_list.json.jbuilder b/app/views/api/v1/product_build_lists/_product_build_list.json.jbuilder new file mode 100644 index 000000000..8dee48d37 --- /dev/null +++ b/app/views/api/v1/product_build_lists/_product_build_list.json.jbuilder @@ -0,0 +1,4 @@ +json.(product_build_list, :id, :status, :time_living) +json.notified_at product_build_list.updated_at +json.url api_v1_product_build_list_path(product_build_list, :format => :json) + diff --git a/app/views/api/v1/product_build_lists/index.json.jbuilder b/app/views/api/v1/product_build_lists/index.json.jbuilder new file mode 100644 index 000000000..2af72653b --- /dev/null +++ b/app/views/api/v1/product_build_lists/index.json.jbuilder @@ -0,0 +1,6 @@ +json.product_build_lists @product_build_lists do |json, product_build_list| + json.partial! 'product_build_list', :product_build_list => product_build_list, :json => json +end + +json.url api_v1_product_build_lists_path(:format => :json) + diff --git a/app/views/api/v1/product_build_lists/show.json.jbuilder b/app/views/api/v1/product_build_lists/show.json.jbuilder new file mode 100644 index 000000000..04362cf4a --- /dev/null +++ b/app/views/api/v1/product_build_lists/show.json.jbuilder @@ -0,0 +1,27 @@ +json.product_build_list do |json| + json.partial! 'product_build_list', :product_build_list => @product_build_list, :json => json + json.(@product_build_list, :commit_hash, :main_script, :params) + + json.product do |json_product| + json.partial! 'api/v1/products/product', + :product => @product_build_list.product, :json => json_product + end + + json.project do |json_project| + json.partial! 'api/v1/projects/project', + :project => @product_build_list.project, :json => json_project + end + + json.arch do |json_arch| + json_arch.(@product_build_list.arch, :id, :name) + end + + json.created_at @product_build_list.created_at.to_i + json.updated_at @product_build_list.updated_at.to_i + + json.results (@product_build_list.results || []) do |json_logs, result| + json_logs.file_name result['file_name'] + json_logs.size result['size'] + json_logs.url "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{result['sha1']}" + end +end diff --git a/config/routes.rb b/config/routes.rb index 4741438f4..2ccc99adf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -75,7 +75,12 @@ Rosa::Application.routes.draw do put :update_member } end - resources :products, :only => [:show, :update, :create, :destroy] + resources :products, :only => [:show, :update, :create, :destroy] do + resources :product_build_lists, :only => :index + end + resources :product_build_lists do + put :cancel, :on => :member + end end end