Sha256: 3363daf49f8b12e720e1e543501eabe83697897c7f25707c1dcb5a772c1b08f3

Contents?: true

Size: 1.16 KB

Versions: 16

Compression:

Stored size: 1.16 KB

Contents

require_dependency "renalware/letters"

module Renalware
  module Letters
    class ListsController < Letters::BaseController
      include Renalware::Concerns::Pageable

      def show
        query = LetterQuery.new(q: params[:q])
        letters = find_and_authorize_letters(query)

        locals = {
          letters: letters,
          authors: User.author.ordered,
          typists: User.ordered,
          q: query.search
        }
        respond_to do |format|
          format.html do
            render locals: locals
          end
          format.js do
            render locals: locals, layout: false
          end
        end
      end

      private

      def find_and_authorize_letters(query)
        collection = call_query(query).page(page).per(per_page)
        present_letters(collection).tap { |letters| authorize letters }
      end

      def present_letters(letters)
        CollectionPresenter.new(letters, LetterPresenterFactory)
      end

      def call_query(query)
        query
          .call
          .with_patient
          .with_main_recipient
          .with_letterhead
          .with_author
          .with_created_by
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
renalware-core-2.0.16 app/controllers/renalware/letters/lists_controller.rb
renalware-core-2.0.15 app/controllers/renalware/letters/lists_controller.rb
renalware-core-2.0.14 app/controllers/renalware/letters/lists_controller.rb
renalware-core-2.0.13 app/controllers/renalware/letters/lists_controller.rb
renalware-core-2.0.12 app/controllers/renalware/letters/lists_controller.rb
renalware-core-2.0.11 app/controllers/renalware/letters/lists_controller.rb
renalware-core-2.0.9 app/controllers/renalware/letters/lists_controller.rb
renalware-core-2.0.8 app/controllers/renalware/letters/lists_controller.rb
renalware-core-2.0.7 app/controllers/renalware/letters/lists_controller.rb
renalware-core-2.0.5 app/controllers/renalware/letters/lists_controller.rb
renalware-core-2.0.4 app/controllers/renalware/letters/lists_controller.rb
renalware-core-2.0.3 app/controllers/renalware/letters/lists_controller.rb
renalware-core-2.0.2 app/controllers/renalware/letters/lists_controller.rb
renalware-core-2.0.1 app/controllers/renalware/letters/lists_controller.rb
renalware-core-2.0.0 app/controllers/renalware/letters/lists_controller.rb
renalware-core-2.0.0.pre.rc13 app/controllers/renalware/letters/lists_controller.rb