added 400 error for API BuildLists#create action

This commit is contained in:
Vokhmin Alexey V 2012-10-10 20:19:00 +04:00
parent 32dca22298
commit 0841c4d705
1 changed files with 17 additions and 11 deletions

View File

@ -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