Skip to content

Added CRUD endpoints for ResourceScores and ResourceDefaultOrders#1915

Open
hepu wants to merge 35 commits into
masterfrom
feature/crud-endpoints
Open

Added CRUD endpoints for ResourceScores and ResourceDefaultOrders#1915
hepu wants to merge 35 commits into
masterfrom
feature/crud-endpoints

Conversation

@hepu
Copy link
Copy Markdown
Contributor

@hepu hepu commented Dec 4, 2025

Summary

  • Adds CRUD-oriented routes for the API endpoints created for ResourceScore and ResourceDefaultOrder

Current routes

image image image image image image image image image

@hepu hepu self-assigned this Dec 4, 2025
@hepu hepu changed the title Added CRUD endpoints for ResourceScores Added CRUD endpoints for ResourceScores and ResourceDefaultOrders Dec 10, 2025
@hepu hepu requested review from andrewroth and frett December 10, 2025 18:05
@stage-branch-merger
Copy link
Copy Markdown

I see you added the "On Staging" label, I'll get this merged to the staging branch!

@stage-branch-merger
Copy link
Copy Markdown

Merge conflict attempting to merge this into staging. Please fix manually.

@stage-branch-merger
Copy link
Copy Markdown

I see you added the "On Staging" label, I'll get this merged to the staging branch!

@stage-branch-merger
Copy link
Copy Markdown

I see you added the "On Staging" label, I'll get this merged to the staging branch!

@stage-branch-merger
Copy link
Copy Markdown

Merge conflict attempting to merge this into staging. Please fix manually.

1 similar comment
@stage-branch-merger
Copy link
Copy Markdown

Merge conflict attempting to merge this into staging. Please fix manually.

@hepu hepu force-pushed the feature/crud-endpoints branch from 995d5c3 to fbde6e6 Compare January 14, 2026 21:54
@stage-branch-merger
Copy link
Copy Markdown

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}]},
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants