Files
turbovault-app/app/controllers/api/v1/collections_controller.rb
2026-03-28 19:24:29 -04:00

50 lines
1.2 KiB
Ruby

module Api
module V1
class CollectionsController < BaseController
before_action :set_collection, only: [ :show, :update, :destroy ]
def index
@collections = current_user.collections.includes(:games).order(:name)
render json: @collections, include: :games
end
def show
render json: @collection, include: :games
end
def create
@collection = current_user.collections.build(collection_params)
if @collection.save
render json: @collection, status: :created
else
render json: { errors: @collection.errors.full_messages }, status: :unprocessable_entity
end
end
def update
if @collection.update(collection_params)
render json: @collection
else
render json: { errors: @collection.errors.full_messages }, status: :unprocessable_entity
end
end
def destroy
@collection.destroy
head :no_content
end
private
def set_collection
@collection = current_user.collections.find(params[:id])
end
def collection_params
params.require(:collection).permit(:name, :description, :parent_collection_id)
end
end
end
end