From 98c1c0d18c21fb57096cf8bf58ba1d15822ade36 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Tue, 10 Dec 2024 08:41:10 +0100 Subject: [PATCH] Group attendance properties into a json key --- app/controllers/groups_controller.rb | 13 +++++++++- spec/requests/groups_spec.rb | 38 ++++++++++++++++------------ 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index f04e394..f53ed35 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -2,7 +2,18 @@ class GroupsController < ApplicationController def index - render json: Groups::SummaryQuery.new.call.as_json + query_result = Groups::SummaryQuery.new.call.as_json.map(&:deep_symbolize_keys).map do |group| + { + id: group[:id], + name: group[:name], + icon: group[:icon], + color: group[:color], + parent_id: group[:parent_id], + attendance: group.slice(:total, :considered, :invited, :confirmed, :declined, :tentative) + } + end + + render json: query_result end def create diff --git a/spec/requests/groups_spec.rb b/spec/requests/groups_spec.rb index 44f755b..bc6267b 100644 --- a/spec/requests/groups_spec.rb +++ b/spec/requests/groups_spec.rb @@ -10,23 +10,29 @@ RSpec.describe 'groups', type: :request do parameter Swagger::Schema::SLUG response(200, 'successful') do schema type: :array, - items: { - type: :object, - required: %i[id name icon parent_id color total considered invited confirmed declined tentative], - properties: { - id: { type: :string, format: :uuid, required: true }, - name: { type: :string }, - icon: { type: :string, example: 'pi pi-crown', description: 'The CSS classes used by the icon' }, - parent_id: { type: :string, format: :uuid }, - color: { type: :string, pattern: '^#(?:[0-9a-fA-F]{3}){1,2}$' }, - total: { type: :integer, minimum: 0, description: 'Total number of guests in any status' }, - considered: { type: :integer, minimum: 0 }, - invited: { type: :integer, minimum: 0 }, - confirmed: { type: :integer, minimum: 0 }, - declined: { type: :integer, minimum: 0 }, - tentative: { type: :integer, minimum: 0 } + items: { + type: :object, + required: %i[id name icon parent_id color attendance], + properties: { + id: { type: :string, format: :uuid, required: true }, + name: { type: :string }, + icon: { type: :string, example: 'pi pi-crown', description: 'The CSS classes used by the icon' }, + parent_id: { type: :string, format: :uuid }, + color: { type: :string, pattern: '^#(?:[0-9a-fA-F]{3}){1,2}$' }, + attendance: { + type: :object, + required: %i[total considered invited confirmed declined tentative], + properties: { + total: { type: :integer, minimum: 0, description: 'Total number of guests in any status' }, + considered: { type: :integer, minimum: 0 }, + invited: { type: :integer, minimum: 0 }, + confirmed: { type: :integer, minimum: 0 }, + declined: { type: :integer, minimum: 0 }, + tentative: { type: :integer, minimum: 0 } + } + } + } } - } xit end regular_api_responses