All checks were successful
		
		
	
	Check usage of free licenses / check-licenses (pull_request) Successful in 1m38s
				
			Add copyright notice / copyright_notice (pull_request) Successful in 3m16s
				
			Run unit tests / unit_tests (pull_request) Successful in 5m31s
				
			Build Nginx-based docker image / build-static-assets (pull_request) Successful in 41m31s
				
			
		
			
				
	
	
		
			47 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| # Copyright (C) 2024-2025 LibreWeddingPlanner contributors
 | |
| 
 | |
| # frozen_string_literal: true
 | |
| 
 | |
| class GroupsController < ApplicationController
 | |
|   def index
 | |
|     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
 | |
|     group = Group.create!(**group_params, parent:)
 | |
|     render json: group.as_json(only: %i[id name icon color parent_id]), status: :created
 | |
|   end
 | |
| 
 | |
|   def update
 | |
|     group = Group.find(params[:id])
 | |
|     group.update!(**group_params, parent:)
 | |
|     render json: group.as_json(only: %i[id name icon color parent_id]), status: :ok
 | |
|   end
 | |
| 
 | |
|   def destroy
 | |
|     Group.find(params[:id]).destroy!
 | |
|     render json: {}, status: :ok
 | |
|   end
 | |
| 
 | |
|   private
 | |
| 
 | |
|   def parent
 | |
|     params[:group][:parent_id].present? ? Group.find(params[:group][:parent_id]) : nil
 | |
|   end
 | |
| 
 | |
|   def group_params
 | |
|     params.expect(group: %i[name icon color])
 | |
|   end
 | |
| end
 |