Skip to content
Snippets Groups Projects
collections_controller.rb 2.21 KiB
Newer Older
class V1::CollectionsController < ApplicationController
  include ::FollowableController
  include ::DeletedObjectsController
  include ::HighlightsController
Giovanne Marcelo's avatar
Giovanne Marcelo committed
  include ::Paginator

Giovanne Marcelo's avatar
Giovanne Marcelo committed
  before_action :set_collection, only: [:show, :update, :destroy, :add_object]
  before_action :authenticate_user!, only: [:create, :update, :destroy]

Giovanne Marcelo's avatar
Giovanne Marcelo committed
    collections = paginate Collection
Giovanne Marcelo's avatar
Giovanne Marcelo committed
    render json: collections
  # GET /v1/collections/1
  # GET /v1/collections/1.json
Giovanne Marcelo's avatar
Giovanne Marcelo committed
      collection.add_items(items_params[:items])
      render json: collection.errors, status: :unprocessable_entity
    end
  end

  # PUT/PATCH /v1/users/1
  # PUT/PATCH /v1/users/1.json
  def update
Giovanne Marcelo's avatar
Giovanne Marcelo committed
      @collection.add_items(items_params[:items])
      render json: @collection.errors, status: :unprocessable_entity
  # DELETE /v1/collections/1
  # DELETE /v1/collections/1.json
    render status: :ok
  # POST /v1/collections/!/items
    render nothing: true, status: :unprocessable_entity if params.nil?
Giovanne Marcelo's avatar
Giovanne Marcelo committed
    @collection.add_items(items_params[:items])
    render json: @collection, status: :ok
  def deleted_resource; Collection; end
  def highlights_resource; Collection; end
  def followable; set_collection; end
  def taggable; set_collection; end
  def sociable; 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
Giovanne Marcelo's avatar
Giovanne Marcelo committed
    params.require(:collection).permit(:name, :description, :owner_id, :owner_type, :privacy, tags: [])
  end

  def items_params
    params.require(:collection).permit(items: [:type, :id, :order])