mirror of
https://github.com/ryankazokas/turbovault-app.git
synced 2026-04-16 22:12:53 +00:00
50 lines
1.2 KiB
Ruby
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
|