Skip to content

Commit

Permalink
update categories and groups controllers to use response_error? helper
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed May 8, 2023
1 parent 706463d commit d2bce04
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions app/controllers/admin/categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def create
begin
category = LinkedData::Client::Models::Category.new(values: category_params)
category_saved = category.save
if category_saved && category_saved.errors
if response_error?(category_saved)
response[:errors] = response_errors(category_saved)
else
response[:success] = "category successfully created in #{Time.now - start}s"
Expand All @@ -52,7 +52,8 @@ def update
category = LinkedData::Client::Models::Category.find_by_acronym(params[:id]).first
category.update_from_params(category_params)
category_update = category.update
if category_update && category_update.errors

if response_error?(category_update)
response[:errors] = response_errors(category_update)
else
response[:success] = "category successfully updated in #{Time.now - start}s"
Expand All @@ -70,7 +71,7 @@ def destroy
category = LinkedData::Client::Models::Category.find_by_acronym(params[:id]).first
error_response = category.delete

if error_response
if response_error?(error_response)
response[:errors] = response_errors(error_response)
else
response[:success] = "category successfully deleted in #{Time.now - start}s"
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/admin/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def create
begin
group = LinkedData::Client::Models::Group.new(values: group_params)
group_saved = group.save
if group_saved && group_saved.errors
if response_error?(group_saved)
response[:errors] = response_errors(group_saved)
else
response[:success] = "group successfully created in #{Time.now - start}s"
Expand All @@ -52,7 +52,7 @@ def update
group = LinkedData::Client::Models::Group.find_by_acronym(params[:id]).first
group.update_from_params(group_params)
group_updated = group.update
if group_updated && group_updated.errors
if response_error?(group_updated)
response[:errors] = response_errors(group_updated)
else
response[:success] = "group successfully updated in #{Time.now - start}s"
Expand All @@ -70,7 +70,7 @@ def destroy
group = LinkedData::Client::Models::Group.find_by_acronym(params[:id]).first
error_response = group.delete

if error_response
if response_error?(error_response)
response[:errors] = response_errors(error_response)
else
response[:success] = "group successfully deleted in #{Time.now - start}s"
Expand Down

0 comments on commit d2bce04

Please sign in to comment.