Skip to content
Snippets Groups Projects
collections_controller.rb 1.71 KiB
Newer Older
class V1::CollectionsController < ApplicationController
  include ::FollowableController
  include ::DeletedObjectsController
  before_action :set_collection, only: [:show, :update, :destroy]
  before_action :authenticate_user!, only: [:create, :update, :destroy]

  def index
    render json: Collection.all
  end

  # GET /v1/collections/1
  # GET /v1/collections/1.json
    if collection.save
      render json: collection, status: :created
      render json: collection.errors, status: :unprocessable_entity
    end
  end

  # PUT/PATCH /v1/users/1
  # PUT/PATCH /v1/users/1.json
  def update
    if @collection.update(collection_params)
      render json: @collection, status: :ok
      render json: @collection.errors, status: :unprocessable_entity
  # DELETE /v1/collections/1
  # DELETE /v1/collections/1.json
    @collection.destroy
    render nothing: true, status: :ok
  def deleted_resource
    Collection
  end

  def taggable
    set_collection
  end

    @collection ||= Collection.find(params[:id])
  end

  # Never trust parameters from the scary internet, only allow the white list through.
  def collection_params
    params.require(:collection).permit(:name, :description, :owner_id, :owner_type, :privacy, tags: [], learning_objects: [])