Sha256: 40e869f9e91a48cb084dfa9030f27544d79b512b1e2abcd47847d448366b2f7c

Contents?: true

Size: 1.63 KB

Versions: 3

Compression:

Stored size: 1.63 KB

Contents

module Locomotive
  module API
    module Resources

      class CurrentSiteResource < Grape::API

        resource :current_site do
          entity_klass = Entities::SiteEntity

          before do
            authenticate_locomotive_account!
            require_site!
          end

          helpers do

            def service
              @service ||= Locomotive::SiteService.new(current_account)
            end

          end

          desc 'Show current_site'
          get do
            authorize current_site, :show?

            present current_site, with: entity_klass
          end


          desc 'Update current site'
          params do
            requires :site, type: Hash do
              optional :name
              optional :handle
              optional :seo_title
              optional :meta_keywords
              optional :meta_description
              optional :robots_txt
              optional :locales, type: Array
              optional :domains, type: Array
              optional :timezone
              optional :picture
            end
          end
          put do
            authorize current_site, :update?

            current_site_form = Forms::SiteForm.new(permitted_params_from_policy(current_site, :site, [:picture]))
            service.update(current_site, current_site_form.serializable_hash)

            present current_site, with: entity_klass
          end


          desc "Delete current site"
          delete do
            authorize current_site, :destroy?

            current_site.destroy

            present current_site, with: entity_klass
          end

        end
      end

    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
locomotivecms-3.0.0.rc5 app/api/locomotive/api/resources/current_site_resource.rb
locomotivecms-3.0.0.rc4 app/api/locomotive/api/resources/current_site_resource.rb
locomotivecms-3.0.0.rc3 app/api/locomotive/api/resources/current_site_resource.rb