diff --git a/app/controllers/api/v1/build_lists_controller.rb b/app/controllers/api/v1/build_lists_controller.rb index 04e1e4bdd..4a783de8b 100644 --- a/app/controllers/api/v1/build_lists_controller.rb +++ b/app/controllers/api/v1/build_lists_controller.rb @@ -14,21 +14,27 @@ class Api::V1::BuildListsController < Api::V1::BaseController end def create - project = Project.find(params[:build_list][:project_id]) - save_to_repository = Repository.find params[:build_list][:save_to_repository_id] #FIXME - params[:build_list][:save_to_platform_id] = save_to_repository.platform_id - params[:build_list][:auto_publish] = false unless save_to_repository.publish_without_qa? + bl_params = params[:build_list] || {} + project = Project.where(:id => bl_params[:project_id]).first + save_to_repository = Repository.where(:id => bl_params[:save_to_repository_id]).first - @build_list = project.build_lists.build(params[:build_list]) - @build_list.project_version = @build_list.commit_hash + if project && save_to_repository + bl_params[:save_to_platform_id] = save_to_repository.platform_id + bl_params[:auto_publish] = false unless save_to_repository.publish_without_qa? - @build_list.user = current_user - @build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority + @build_list = project.build_lists.build(bl_params) + @build_list.project_version = @build_list.commit_hash - if @build_list.save - render :action => 'show' + @build_list.user = current_user + @build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority + + if @build_list.save + render :action => 'show' + else + render :json => {:message => "Validation Failed", :errors => @build_list.errors.messages}.to_json, :status => 422 + end else - render :json => {:message => "Validation Failed", :errors => @build_list.errors.messages}.to_json, :status => 422 + render :json => {:message => "Bad Request"}.to_json, :status => 400 end end