Class: Renalware::Patients::BookmarksController

Inherits:
BaseController show all
Includes:
Concerns::Pageable
Defined in:
app/controllers/renalware/patients/bookmarks_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#patient

Instance Method Details

#createObject

idempotent



22
23
24
25
26
27
28
# File 'app/controllers/renalware/patients/bookmarks_controller.rb', line 22

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

#destroyObject

idempotent rubocop:disable Metrics/AbcSize



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/renalware/patients/bookmarks_controller.rb', line 32

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

#indexObject

Display the user’s bookmarks



10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/renalware/patients/bookmarks_controller.rb', line 10

def index
  search = BookmarksQuery.new(
    default_relation: Patients.cast_user(current_user).bookmarks,
    params: params[:q]
  ).search

  bookmarks = search.result.page(page).per(per_page)
  authorize bookmarks
  render locals: { bookmarks: bookmarks, search: search }
end