Sha256: 883fc74aa7f38ed3efbf7bd6daae1946a2e5b932ea40d063a96484190020add5

Contents?: true

Size: 1.35 KB

Versions: 22

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/letters"

module Renalware
  module Letters
    module Mailshots
      class MailshotsController < BaseController
        include Pagy::Backend

        def index
          pagy, mailshots = pagy(Mailshot.includes(:author).order(created_at: :desc))
          authorize mailshots
          render locals: { mailshots: mailshots, pagy: pagy }
        end

        def new
          mailshot = Mailshot.new
          authorize mailshot
          render_new(mailshot)
        end

        def create
          mailshot = Mailshot.new(mailshot_params)
          authorize mailshot, :create?
          mailshot.letters_count = mailshot.recipient_patients.length
          mailshot.status = "queued"

          if mailshot.save_by(current_user)
            CreateMailshotLettersJob.perform_later(mailshot)
            redirect_to letters_mailshots_path, notice: "Mailshot queued for background processing"
          else
            render_new(mailshot)
          end
        end

        private

        def render_new(mailshot)
          render :new, locals: { mailshot: mailshot }
        end

        def mailshot_params
          params
            .require(:mailshot)
            .permit(
              :letterhead_id, :description, :author_id, :body, :sql_view_name
            )
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/controllers/renalware/letters/mailshots/mailshots_controller.rb
renalware-core-2.1.0 app/controllers/renalware/letters/mailshots/mailshots_controller.rb
renalware-core-2.0.167 app/controllers/renalware/letters/mailshots/mailshots_controller.rb
renalware-core-2.0.166 app/controllers/renalware/letters/mailshots/mailshots_controller.rb
renalware-core-2.0.165 app/controllers/renalware/letters/mailshots/mailshots_controller.rb
renalware-core-2.0.164 app/controllers/renalware/letters/mailshots/mailshots_controller.rb
renalware-core-2.0.163 app/controllers/renalware/letters/mailshots/mailshots_controller.rb
renalware-core-2.0.162 app/controllers/renalware/letters/mailshots/mailshots_controller.rb
renalware-core-2.0.161 app/controllers/renalware/letters/mailshots/mailshots_controller.rb
renalware-core-2.0.160 app/controllers/renalware/letters/mailshots/mailshots_controller.rb
renalware-core-2.0.159 app/controllers/renalware/letters/mailshots/mailshots_controller.rb
renalware-core-2.0.158 app/controllers/renalware/letters/mailshots/mailshots_controller.rb
renalware-core-2.0.157 app/controllers/renalware/letters/mailshots/mailshots_controller.rb
renalware-core-2.0.156 app/controllers/renalware/letters/mailshots/mailshots_controller.rb
renalware-core-2.0.155 app/controllers/renalware/letters/mailshots/mailshots_controller.rb
renalware-core-2.0.153 app/controllers/renalware/letters/mailshots/mailshots_controller.rb
renalware-core-2.0.152 app/controllers/renalware/letters/mailshots/mailshots_controller.rb
renalware-core-2.0.151 app/controllers/renalware/letters/mailshots/mailshots_controller.rb
renalware-core-2.0.149 app/controllers/renalware/letters/mailshots/mailshots_controller.rb
renalware-core-2.0.148 app/controllers/renalware/letters/mailshots/mailshots_controller.rb