Added CRUD endpoints for ResourceScores and ResourceDefaultOrders#1915
Added CRUD endpoints for ResourceScores and ResourceDefaultOrders#1915hepu wants to merge 35 commits into
Conversation
…endpoint for ranked resources
|
I see you added the "On Staging" label, I'll get this merged to the staging branch! |
|
Merge conflict attempting to merge this into staging. Please fix manually. |
|
I see you added the "On Staging" label, I'll get this merged to the staging branch! |
|
I see you added the "On Staging" label, I'll get this merged to the staging branch! |
|
Merge conflict attempting to merge this into staging. Please fix manually. |
1 similar comment
|
Merge conflict attempting to merge this into staging. Please fix manually. |
995d5c3 to
fbde6e6
Compare
|
I see you added the "On Staging" label, I'll get this merged to the staging branch! |
| @resource_score = ResourceScore.find(params[:id]) | ||
| @resource_score.destroy! | ||
| render json: {}, status: :ok | ||
| rescue |
There was a problem hiding this comment.
Below references e.message but no exception e (rescue => e) is done here.
| @resource_default_order.destroy! | ||
| render json: {}, status: :ok | ||
| rescue | ||
| render json: {errors: [{source: {pointer: "/data/attributes/id"}, detail: e.message}]}, |
There was a problem hiding this comment.
Below references e.message but no exception e (rescue => e) is done here.
| resource_type = params.dig(:filter, :resource_type) || params[:resource_type] | ||
|
|
||
| if lang.present? | ||
| language = Language.where("code = :lang OR LOWER(code) = LOWER(:lang)", lang: lang).first |
There was a problem hiding this comment.
code = :lang is redundant if LOWER(code) = LOWER(:lang) (even better if it can be refactored to one method/scope)
| def create | ||
| sanitized_params = create_params | ||
| if create_params[:lang].present? | ||
| language = Language.where("code = :lang OR LOWER(code) = LOWER(:lang)", |
There was a problem hiding this comment.
code = :lang is redundant if LOWER(code) = LOWER(:lang)
| @resource_default_order = ResourceDefaultOrder.find(params[:id]) | ||
| sanitized_params = create_params | ||
| if create_params[:lang].present? | ||
| language = Language.where("code = :lang OR LOWER(code) = LOWER(:lang)", |
There was a problem hiding this comment.
code = :lang is redundant if LOWER(code) = LOWER(:lang)
| @resource_default_order.language = language if language.present? | ||
| @resource_default_order.save! | ||
| render json: @resource_default_order, status: :created | ||
| rescue => e |
There was a problem hiding this comment.
all of these => e catches should really grab a subset of errors like record not found etc. Otherwise, we end up catching errors that should go to a rollbar crash report (bugs).
| class ConvertResourceScoreLangToLanguageId < ActiveRecord::Migration[7.1] | ||
| def up | ||
| add_column :resource_scores, :language_id, :integer | ||
| add_index :resource_scores, [:language_id, :country] |
There was a problem hiding this comment.
| add_index :resource_scores, [:language_id, :country] | |
| add_index :resource_scores, [:resource_id, :language_id, :country], unique: true |
I believe this won't break anything and is better than not having it. But whoever deploys this needs to query production data to make sure this will apply on production data.
| end | ||
|
|
||
| def down | ||
| remove_index :resource_scores, [:language_id, :country] if index_exists?(:resource_scores, [:language_id, :country]) |
There was a problem hiding this comment.
| remove_index :resource_scores, [:language_id, :country] if index_exists?(:resource_scores, [:language_id, :country]) | |
| remove_index :resource_scores, [:resource_id, :language_id, :country] if index_exists?(:resource_scores, [:resource_id, :language_id, :country]) |
| class ConvertResourceDefaultOrderLangToLanguageId < ActiveRecord::Migration[7.1] | ||
| def up | ||
| add_column :resource_default_orders, :language_id, :integer | ||
| add_index :resource_default_orders, :language_id |
There was a problem hiding this comment.
| add_index :resource_default_orders, :language_id | |
| add_index :resource_default_orders, [:resource_id, :language_id], unique: true |
|
|
||
| def down | ||
| if column_exists?(:resource_default_orders, :language_id) | ||
| remove_index :resource_default_orders, :language_id |
There was a problem hiding this comment.
| remove_index :resource_default_orders, :language_id | |
| remove_index :resource_default_orders, [:resource_id, :language_id] if index_exists?(:resource_default_orders, [:resource_id, :language_id]) |
Summary
ResourceScoreandResourceDefaultOrderCurrent routes