From 6eb061c01e78caeac7a2688fb7aa188c8f402bf4 Mon Sep 17 00:00:00 2001 From: Marek Takac Date: Tue, 17 Jun 2014 17:23:39 +0200 Subject: [PATCH] Simplified #star endpoint --- lib/api/root.rb | 3 +++ lib/api/v3/queries/queries_api.rb | 13 +++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/api/root.rb b/lib/api/root.rb index 31926746b1..dd74cc478d 100644 --- a/lib/api/root.rb +++ b/lib/api/root.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 diff --git a/lib/api/v3/queries/queries_api.rb b/lib/api/v3/queries/queries_api.rb index 01bc35d437..898c3012b5 100644 --- a/lib/api/v3/queries/queries_api.rb +++ b/lib/api/v3/queries/queries_api.rb @@ -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