wedding-planner/app/queries/groups/summary_query.rb
Manuel Bustillo 452b5b2040
All checks were successful
Check usage of free licenses / build-static-assets (pull_request) Successful in 45s
Add copyright notice / copyright_notice (pull_request) Successful in 1m47s
Run unit tests / unit_tests (pull_request) Successful in 5m4s
Introduce endpoint to retrieve a summary of groups and invite attendance
2024-11-13 08:57:20 +01:00

30 lines
790 B
Ruby

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