mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 17:41:17 +08:00
Extract queries to keep logic in the Categories Model
This creates two methods in the Category model. This moves the model logic to the model and just calls the Category class methods in ListController. This also adds tests for the two methods created in the Category model. The motivation for this refactor is the code climate score of the this class and readability of the code. Please enter the commit message for your changes. Lines starting
This commit is contained in:
@ -214,13 +214,12 @@ class ListController < ApplicationController
|
||||
|
||||
parent_category_id = nil
|
||||
if parent_slug_or_id.present?
|
||||
parent_category_id = Category.where(slug: parent_slug_or_id).pluck(:id).first ||
|
||||
Category.where(id: parent_slug_or_id.to_i).pluck(:id).first
|
||||
parent_category_id = Category.query_parent_category(parent_slug_or_id)
|
||||
raise Discourse::NotFound.new if parent_category_id.blank?
|
||||
end
|
||||
|
||||
@category = Category.where(slug: slug_or_id, parent_category_id: parent_category_id).includes(:featured_users).first ||
|
||||
Category.where(id: slug_or_id.to_i, parent_category_id: parent_category_id).includes(:featured_users).first
|
||||
@category = Category.query_category(slug_or_id, parent_category_id)
|
||||
|
||||
guardian.ensure_can_see!(@category)
|
||||
|
||||
raise Discourse::NotFound.new if @category.blank?
|
||||
|
Reference in New Issue
Block a user