2024-11-13 07:59:07 +00:00
|
|
|
# Copyright (C) 2024 Manuel Bustillo
|
|
|
|
|
2024-11-13 08:57:20 +01:00
|
|
|
module Groups
|
|
|
|
class SummaryQuery
|
|
|
|
def call
|
|
|
|
ActiveRecord::Base.connection.execute(query).to_a
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def query
|
|
|
|
<<~SQL.squish
|
|
|
|
SELECT#{' '}
|
|
|
|
groups.id,
|
|
|
|
groups.name,
|
|
|
|
groups.icon,
|
|
|
|
groups.parent_id,
|
|
|
|
groups.color,
|
|
|
|
count(*) filter (where status IS NOT NULL) as total,
|
|
|
|
count(*) filter (where status = 0) as considered,
|
|
|
|
count(*) filter (where status = 10) as invited,
|
|
|
|
count(*) filter (where status = 20) as confirmed,
|
|
|
|
count(*) filter (where status = 30) as declined,
|
|
|
|
count(*) filter (where status = 40) as tentative
|
|
|
|
FROM groups
|
|
|
|
LEFT JOIN guests on groups.id = guests.group_id
|
|
|
|
GROUP BY groups.id
|
|
|
|
SQL
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|