2024-10-27 21:42:45 +00:00
|
|
|
# Copyright (C) 2024 Manuel Bustillo
|
|
|
|
|
2024-08-11 16:29:10 +02:00
|
|
|
class GroupsController < ApplicationController
|
|
|
|
def index
|
2024-11-13 08:57:20 +01:00
|
|
|
render json: Groups::SummaryQuery.new.call.as_json
|
2024-08-11 16:29:10 +02:00
|
|
|
end
|
2024-12-08 11:30:38 +01:00
|
|
|
|
|
|
|
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: [:name, :icon, :color])
|
|
|
|
end
|
2024-08-11 16:29:10 +02:00
|
|
|
end
|