wedding-planner/app/controllers/groups_controller.rb

34 lines
789 B
Ruby
Raw Normal View History

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
render json: Groups::SummaryQuery.new.call.as_json
2024-08-11 16:29:10 +02:00
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: [:name, :icon, :color])
end
2024-08-11 16:29:10 +02:00
end