Sha256: 968336af0ab115d50442ccaa83cf5cd2f9b75ae191909e860bb58232faa0cfdd

Contents?: true

Size: 1.3 KB

Versions: 23

Compression:

Stored size: 1.3 KB

Contents

module TypeStation
  module Admin
    class EntitiesController < ::TypeStation::AdminController

      def create
        @entity = Mongoid::Factory.build TypeStation::Entity, '_type' => params[:_type].classify

        if params[:parent_id]
          parent_entity = TypeStation::Entity.find(params[:parent_id])
          @entity.parent = parent_entity
        end

        if @entity.update_contents(contents)
          render json: { status: :success, entity: @entity }, status: :ok
        else
          render json: @entity.errors, status: :unprocessable_entity
        end
      end

      def update
        @entity = TypeStation::Entity.find(params[:id])

        if params[:direction]
          @entity.move_entity params[:direction]
        end

        if @entity.update_contents(contents)
          render json: { status: :success }, status: :ok
        else
          render json: @entity.errors, status: :unprocessable_entity
        end
      end

      def destroy
        @entity = TypeStation::Entity.find(params[:id])

        if @entity.delete
          render json: { status: :success }, status: :ok
        else
          render json: @entity.errors, status: :unprocessable_entity
        end
      end


      private

      def contents
        [params[:contents]].compact.flatten
      end

    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
type_station-0.7.0 app/controllers/type_station/admin/entities_controller.rb
type_station-0.6.0 app/controllers/type_station/admin/entities_controller.rb
type_station-0.5.4 app/controllers/type_station/admin/entities_controller.rb
type_station-0.5.3 app/controllers/type_station/admin/entities_controller.rb
type_station-0.5.2 app/controllers/type_station/admin/entities_controller.rb
type_station-0.5.1 app/controllers/type_station/admin/entities_controller.rb
type_station-0.4.7 app/controllers/type_station/admin/entities_controller.rb
type_station-0.4.6 app/controllers/type_station/admin/entities_controller.rb
type_station-0.4.5 app/controllers/type_station/admin/entities_controller.rb
type_station-0.4.4 app/controllers/type_station/admin/entities_controller.rb
type_station-0.4.3 app/controllers/type_station/admin/entities_controller.rb
type_station-0.4.2 app/controllers/type_station/admin/entities_controller.rb
type_station-0.4.1 app/controllers/type_station/admin/entities_controller.rb
type_station-0.4.0 app/controllers/type_station/admin/entities_controller.rb
type_station-0.3.4 app/controllers/type_station/admin/entities_controller.rb
type_station-0.3.3 app/controllers/type_station/admin/entities_controller.rb
type_station-0.3.2 app/controllers/type_station/admin/entities_controller.rb
type_station-0.3.1 app/controllers/type_station/admin/entities_controller.rb
type_station-0.3.0 app/controllers/type_station/admin/entities_controller.rb
type_station-0.2.3 app/controllers/type_station/admin/entities_controller.rb