Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_refinement_order_status_check
is_international = params[:is_international].to_i
is_external = params[:is_external].to_i # 0: 指定なし(ALL) 1: true 2: false

@groups = Group.all
@groups = Group.with_order_status_check_relations
@groups = @groups.where(fes_year_id: fes_year_id) unless fes_year_id == 0
@groups = @groups.where(group_category_id: group_category_id) unless group_category_id == 0
@groups = @groups.where(is_international: is_international == 1) unless is_international == 0
Expand All @@ -58,11 +58,12 @@ def get_refinement_order_status_check
# あいまい検索機能
def get_search_order_status_check
word = params[:word]
@groups = Group.with_order_status_check_narrow_down_by_search_word(word)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

で、with_order_status_check_narrow_down_by_search_wordが使われなくなるからmodelsにあるやつ消してもいいと思う。
レスポンス違うのかなと思ったんだけど、下の変更でfit_groupの型で返ってくるようになってたから削除しちゃっても問題なさそう。
render json: fmt(ok, @groups)
render json: fmt(ok, fit_group_index_for_admin_view(@groups))

@groups = Group.with_order_status_check_relations.where('name LIKE ?', "%#{word}%")

if @groups.none?
render json: fmt(not_found, [], 'Not found groups')
else
render json: fmt(ok, @groups)
render json: fmt(ok, fit_group_index_for_admin_view(@groups))
end
end
end
84 changes: 20 additions & 64 deletions api/app/models/group.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
# frozen_string_literal: true

class Group < ApplicationRecord
ORDER_STATUS_CHECK_INCLUDES = [
:user,
:group_category,
:fes_year,
:sub_rep,
:place_order,
:stage_orders,
:stage_common_option,
:power_orders,
:rental_orders,
:employees,
:public_relation,
:venue_map,
:announcement,
:cooking_process_order,
{ food_products: :purchase_lists }
].freeze

belongs_to :user
belongs_to :fes_year
belongs_to :group_category
Expand All @@ -21,6 +39,8 @@ class Group < ApplicationRecord
has_many :un_registered_groups, dependent: :destroy
has_many :fire_equipment_orders, dependent: :destroy

scope :with_order_status_check_relations, -> { includes(*ORDER_STATUS_CHECK_INCLUDES) }

### group_category (参加団体カテゴリ)

# 全てのgroupとそのgroup_categoryを取得する
Expand Down Expand Up @@ -415,70 +435,6 @@ def self.with_order_status_check(group_id)
return @record
end

# 指定したfes_yearに対応するgroupとそれが持つorderを取得する
def self.with_order_status_check_narrow_down_by_fes_year(fes_year_id)
@record = Group.where(groups: { fes_year_id: fes_year_id })
.map do |group|
{
group: group,
user: group.user&.id,
group_category: group.group_category&.id,
fes_year: group.fes_year&.id,
sub_rep: group.sub_rep&.id,
place_order: group.place_order&.id,
stage_orders: group.stage_orders.none? ? nil : group.stage_orders[0].id,
stage_common_option: group.stage_common_option&.id,
power_orders: group.power_orders.none? ? nil : group.power_orders[0].id,
rental_orders: group.rental_orders.none? ? nil : group.rental_orders[0].id,
employees: group.employees.none? ? nil : group.employees[0].id,
food_products: if group.food_products.empty?
nil
else
{
food_product: group.food_products.first&.id,
purchase_lists: group.food_products.first.nil? || group.food_products.first.purchase_lists.empty? ? nil : group.food_products.first.purchase_lists[0].id
}
end,
public_relation: group.public_relation&.id,
venue_map: group.venue_map&.id,
announcement: group.announcement&.id,
cooking_process_order: group.cooking_process_order&.id
}
end
end

# 検索ワードに対応するgroupとそれが持つorderを取得する
def self.with_order_status_check_narrow_down_by_search_word(word)
@record = Group.where('name like ?', "%#{word}%")
.map do |group|
{
group: group,
user: group.user&.id,
group_category: group.group_category&.id,
fes_year: group.fes_year&.id,
sub_rep: group.sub_rep&.id,
place_order: group.place_order&.id,
stage_orders: group.stage_orders.none? ? nil : group.stage_orders[0].id,
stage_common_option: group.stage_common_option&.id,
power_orders: group.power_orders.none? ? nil : group.power_orders[0].id,
rental_orders: group.rental_orders.none? ? nil : group.rental_orders[0].id,
employees: group.employees.none? ? nil : group.employees[0].id,
food_products: if group.food_products.empty?
nil
else
{
food_product: group.food_products.first&.id,
purchase_lists: group.food_products.first.nil? || group.food_products.first.purchase_lists.empty? ? nil : group.food_products.first.purchase_lists[0].id
}
end,
public_relation: group.public_relation&.id,
venue_map: group.venue_map&.id,
announcement: group.announcement&.status,
cooking_process_order: group.cooking_process_order&.id
}
end
end

### sub rep (副代表)

# 全てのgroupとそのsub_repを取得する
Expand Down
Loading