Sha256: 5162b4e7a416536b05d5e086342b9a52a869ed5e73159f51ad190ad669b4dc3b

Contents?: true

Size: 1.16 KB

Versions: 20

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

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

      # 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

20 entries across 20 versions & 1 rubygems

Version Path
renalware-core-2.0.38 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.37 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.36 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.35 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.34 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.33 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.32 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.31 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.30 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.28 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.27 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.26 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.25 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.24 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.23 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.22 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.21 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.20 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.18 app/controllers/renalware/patients/bookmarks_controller.rb
renalware-core-2.0.17 app/controllers/renalware/patients/bookmarks_controller.rb