Sha256: 7bbf8eac44e3f77f6f60bed41066bde324a6c36d12946b35a247acee32740094

Contents?: true

Size: 904 Bytes

Versions: 9

Compression:

Stored size: 904 Bytes

Contents

# frozen_string_literal: true

module Maglev
  module Api
    class AssetsController < ::Maglev::ApiController
      include ::ActiveStorage::SetCurrent

      def index
        @assets = resources.search(
          params[:query], params[:asset_type], params[:page], params[:per_page]
        )
      end

      def show
        @asset = resources.find(params[:id])
      end

      def create
        asset = resources.create!(asset_params)
        head :created, location: api_asset_path(asset), maglev_asset_id: asset.id
      end

      def update
        resources.find(params[:id]).update!(asset_params)
        head :ok
      end

      def destroy
        resources.find(params[:id]).destroy!
        head :no_content
      end

      private

      def asset_params
        params.require(:asset).permit(:file)
      end

      def resources
        ::Maglev::Asset
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
maglevcms-1.4.0 app/controllers/maglev/api/assets_controller.rb
maglevcms-1.3.0 app/controllers/maglev/api/assets_controller.rb
maglevcms-1.2.2 app/controllers/maglev/api/assets_controller.rb
maglevcms-1.2.1 app/controllers/maglev/api/assets_controller.rb
maglevcms-1.2.0 app/controllers/maglev/api/assets_controller.rb
maglevcms-1.1.7 app/controllers/maglev/api/assets_controller.rb
maglevcms-1.1.6 app/controllers/maglev/api/assets_controller.rb
maglevcms-1.1.5 app/controllers/maglev/api/assets_controller.rb
maglevcms-1.1.4 app/controllers/maglev/api/assets_controller.rb