Class: Admin::AdoptionContacts::IndexPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/admin/adoption_contacts/index_presenter.rb

Instance Method Summary collapse

Constructor Details

#initialize(user, page, query, animal_id) ⇒ IndexPresenter

Returns a new instance of IndexPresenter.


2
3
4
5
6
7
# File 'app/presenters/admin/adoption_contacts/index_presenter.rb', line 2

def initialize(user, page, query, animal_id)
  @user = user
  @query = query
  @page = page
  @animal_id = animal_id
end

Instance Method Details

#adoption_contactsObject


9
10
11
# File 'app/presenters/admin/adoption_contacts/index_presenter.rb', line 9

def adoption_contacts
  search.result.paginate(page: @page, per_page: 10).order(updated_at: :desc)
end

#animalObject


21
22
23
# File 'app/presenters/admin/adoption_contacts/index_presenter.rb', line 21

def animal
  Animal.organization(@user).order(name: :asc)
end

#searchObject


13
14
15
16
17
18
19
# File 'app/presenters/admin/adoption_contacts/index_presenter.rb', line 13

def search
  if @animal_id
    AdoptionContact.joins(:adopt_animals).organization(@user).where(adopt_animals: {animal_id: @animal_id}).search(@query)
  else
    AdoptionContact.organization(@user).search(@query)
  end
end