Class: CabooseRets::SavedPropertiesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/caboose_rets/saved_properties_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject

GET /saved-properties



5
6
7
8
9
# File 'app/controllers/caboose_rets/saved_properties_controller.rb', line 5

def index
  return if !verify_logged_in
  @page.title = "Saved Listings"
  @saved = SavedProperty.where(:user_id => logged_in_user.id).all
end

#rets_infoObject

GET /admin/users/:id/mls



12
13
14
15
16
# File 'app/controllers/caboose_rets/saved_properties_controller.rb', line 12

def rets_info
  @edituser = Caboose::User.where(:id => params[:id], :site_id => @site.id).first
  @saved = SavedProperty.where(:user_id => @edituser.id).order('date_saved desc').all
  render :layout => 'caboose/admin'
end

#saveObject

PUT /api/save-property



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/caboose_rets/saved_properties_controller.rb', line 25

def save
  return if !verify_logged_in
  resp = Caboose::StdClass.new
  if SavedProperty.exists?(:user_id => logged_in_user.id, :mls_number => params[:mls])
    resp.success = true
  else
    p = SavedProperty.new(
      :user_id  => logged_in_user.id,
      :mls_number => params[:mls],
      :date_saved => DateTime.now
    )
    if p.save
      resp.success = true
    else
      resp.error = "There was an error saving your property."
    end
  end
  render :json => resp
end

#statusObject

GET /saved-properties/:mls/status



74
75
76
77
78
79
80
# File 'app/controllers/caboose_rets/saved_properties_controller.rb', line 74

def status
  return if !verify_logged_in

  resp = Caboose::StdClass.new
  resp.saved = SavedProperty.where(:user_id => logged_in_user.id, :mls => params[:mls]).exists?
  render :json => resp
end

#unsaveObject

PUT /api/unsave-property



46
47
48
49
50
# File 'app/controllers/caboose_rets/saved_properties_controller.rb', line 46

def unsave
  return if !verify_logged_in
  SavedProperty.where(:user_id => logged_in_user.id, :mls_number => params[:mls]).destroy_all
  render :json => Caboose::StdClass.new('success' => true)
end

#user_reportObject

GET /admin/mls/user-report



19
20
21
22
# File 'app/controllers/caboose_rets/saved_properties_controller.rb', line 19

def user_report
  @users = Caboose::User.where(:site_id => @site.id).where("rets_agent_mls_id is not null").order('id desc').limit(500)
  render :layout => 'caboose/admin'
end