#671: added API #update action for platform
This commit is contained in:
parent
32dca22298
commit
abe31b3c2e
|
@ -18,4 +18,22 @@ class Api::V1::PlatformsController < Api::V1::BaseController
|
|||
@platforms = Platform.main.opened.paginate(:page => params[:page], :per_page => 20)
|
||||
render :index
|
||||
end
|
||||
|
||||
def update
|
||||
p = params[:platform] || {}
|
||||
owner = User.where(:id => p[:owner_id]).first
|
||||
platform_params = {}
|
||||
platform_params[:owner] = owner if owner
|
||||
platform_params[:released] = p[:released] if p[:released]
|
||||
platform_params[:description] = p[:description] if p[:description]
|
||||
if @platform.update_attributes(p)
|
||||
render :json => {
|
||||
:platform => {:id => @platform.id,
|
||||
:message => 'Platform has been updated successfully'}
|
||||
}.to_json
|
||||
else
|
||||
render :json => {:message => "Validation Failed", :errors => @platform.errors.messages}.to_json, :status => 422
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -20,6 +20,7 @@ class Platform < ActiveRecord::Base
|
|||
has_many :mass_builds
|
||||
|
||||
validates :description, :presence => true
|
||||
validates :owner, :presence => true
|
||||
validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES}
|
||||
validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-\.]+$/ }
|
||||
validates :distrib_type, :presence => true, :inclusion => {:in => APP_CONFIG['distr_types']}
|
||||
|
@ -167,7 +168,7 @@ class Platform < ActiveRecord::Base
|
|||
|
||||
def update_owner_relation
|
||||
if owner_id_was != owner_id
|
||||
r = relations.where(:actor_id => owner_id_was, :actor_type => owner_type_was)[0]
|
||||
r = relations.where(:actor_id => owner_id_was, :actor_type => owner_type_was).first
|
||||
r.update_attributes(:actor_id => owner_id, :actor_type => owner_type)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ json.platforms @platforms do |json, platform|
|
|||
end
|
||||
json.repositories platform.repositories do |json_repos, repo|
|
||||
json_repos.(repo, :id, :name)
|
||||
json_repos.url api_v1_repository_path(repo.name, :format => :json)
|
||||
json_repos.url api_v1_repository_path(repo.id, :format => :json)
|
||||
end
|
||||
json.url api_v1_platform_path(platform.name, :format => :json)
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ json.platform do |json|
|
|||
end
|
||||
json.repositories @platform.repositories do |json_repos, repo|
|
||||
json_repos.(repo, :id, :name)
|
||||
json_repos.url api_v1_repository_path(repo.name, :format => :json)
|
||||
json_repos.url api_v1_repository_path(repo.id, :format => :json)
|
||||
end
|
||||
end
|
||||
json.url api_v1_platform_path(@platform, :format => :json)
|
||||
|
|
Loading…
Reference in New Issue