mirror of
https://github.com/ryankazokas/turbovault-app.git
synced 2026-04-17 01:42:53 +00:00
Moving to github
This commit is contained in:
49
app/controllers/api/v1/collections_controller.rb
Normal file
49
app/controllers/api/v1/collections_controller.rb
Normal file
@@ -0,0 +1,49 @@
|
||||
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
|
||||
Reference in New Issue
Block a user