Simplified #star endpoint

pull/1471/head
Marek Takac 11 years ago
parent 88b1c64b26
commit 6eb061c01e
  1. 3
      lib/api/root.rb
  2. 13
      lib/api/v3/queries/queries_api.rb

@ -66,6 +66,9 @@ module API
when 'ActiveRecord::RecordNotFound'
not_found = API::Errors::NotFound.new(e.message)
Rack::Response.new(not_found.to_json, not_found.code, not_found.headers).finish
when 'ActiveRecord::RecordInvalid'
error = API::Errors::Validation.new(e.record)
Rack::Response.new(error.to_json, error.code, error.headers).finish
end
end

@ -27,14 +27,11 @@ module API
patch :star do
authorize(:queries, :star, project: @query.project, allow: allowed_to_manage_stars?)
normalized_query_name = @query.name.parameterize.underscore
query_menu_item = MenuItems::QueryMenuItem.find_or_initialize_by_name_and_navigatable_id normalized_query_name, @query.id, title: @query.name
if query_menu_item.valid?
query_menu_item.save!
@representer.to_json
else
raise ValidationError.new(query_menu_item)
end
query_menu_item = MenuItems::QueryMenuItem.find_or_initialize_by_name_and_navigatable_id(
normalized_query_name, @query.id, title: @query.name
)
query_menu_item.save!
@representer.to_json
end
patch :unstar do

Loading…
Cancel
Save