Sha256: c3d1031ccc053adf1c80cacc577707abde84d8936da70d69b444a86129901d2c

Contents?: true

Size: 1.44 KB

Versions: 24

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module Renalware
  module Patients
    class BookmarksController < BaseController
      before_action :load_patient, only: :create

      # Display the user's bookmarks
      def index
        bookmarks = Patients.cast_user(current_user)
          .bookmarks
          .ordered
          .includes(patient: [current_modality: :description])
        authorize bookmarks
        render locals: { bookmarks: bookmarks }
      end

      # idempotent
      def create
        Bookmark.find_or_create_by!(user: user, patient: patient) do |bookmark|
          bookmark.assign_attributes(bookmark_params)
        end
        redirect_back(fallback_location: patient_path(patient),
                      notice: success_msg_for("bookmark"))
      end

      # idempotent
      def destroy
        bookmark = user.bookmarks.find_by(id: params[:id])
        patient = bookmark&.patient
        if bookmark.present?
          authorize bookmark
          bookmark.destroy
        else
          skip_authorization
        end
        fallback_location = patient.presence || root_path
        redirect_back(fallback_location: patient_path(fallback_location),
                      notice: success_msg_for("bookmark"))
      end

      private

      def user
        @user ||= Renalware::Patients.cast_user(current_user)
      end

      def bookmark_params
        params.require(:patients_bookmark).permit(:notes, :urgent, :tags)
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
renalware-core-2.0.64 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.63 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.62 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.61 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.60 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.58 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.57 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.56 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.55 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.54 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.53 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.52 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.51 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.50 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.48 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.47 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.46 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.45 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.44 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.43 app/controllers/renalware/patients/bookmarks_controller.rb