From de93ffb643570f997e16f9868b85576bfe9e75bb Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 11 Aug 2024 18:56:38 +0200 Subject: [PATCH] Return number of guests per group --- app/controllers/groups_controller.rb | 3 ++- app/serializers/serializable_group.rb | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 461a67f..0f489fb 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -1,5 +1,6 @@ class GroupsController < ApplicationController def index - render jsonapi: Group.where(parent_id: nil), include: [children: [children: [:children]]] + roots = Group.where(parent_id: nil) + render jsonapi: roots, include: [children: [children: [:children]]] end end diff --git a/app/serializers/serializable_group.rb b/app/serializers/serializable_group.rb index e90dc52..f832475 100644 --- a/app/serializers/serializable_group.rb +++ b/app/serializers/serializable_group.rb @@ -4,4 +4,8 @@ class SerializableGroup < JSONAPI::Serializable::Resource attributes :name, :icon has_many :children + + attribute :guest_count do + @object.guests.count + end end