Class: CabooseRets::SavedSearchesController

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

Instance Method Summary collapse

Instance Method Details

#addObject

POST /saved-searches



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/caboose_rets/saved_searches_controller.rb', line 12

def add
  return if !verify_logged_in      
  
  resp = Caboose::StdClass.new
  
  if SavedSearch.exists?(:uri => params[:uri])
    resp.redirect = "/saved-searches"
  else        
    search = SavedSearch.new(
      :user_id        => logged_in_user.id,
      :date_last      => Date.today,
      :interval       => 1,
      :notify         => true,
      :uri            => params[:uri],
      :property_type  => params[:property_type],
      :params         => params[:params]        
    )
    if search.save
      resp.redirect = "/saved-searches"        
    else
      resp.error = "There was an error saving your search."        
    end
  end
  render :json => resp
end

#deleteObject

DELETE /saved-searches/:id



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/caboose_rets/saved_searches_controller.rb', line 65

def delete
  return if !verify_logged_in
  
  resp = Caboose::StdClass.new               
  search = SavedSearch.find(params[:id])
  
  if search
    search.destroy
    resp.success = "The saved search has been deleted."                
  else
    resp.error = "There was an error deleting your search."        
  end
  
  render :json => resp
end

#indexObject

GET /saved-searches



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

def index
  return if !verify_logged_in
  @searches = SavedSearch.where(:user_id => logged_in_user.id).all
  render :layout => 'caboose/modal'
end

#redirectObject

GET /saved-searches/:id



39
40
41
42
43
# File 'app/controllers/caboose_rets/saved_searches_controller.rb', line 39

def redirect
  return if !verify_logged_in
  @search = SavedSearch.find(params[:id])
  redirect_to @search.uri      
end

#updateObject

PUT /saved-searches/:id



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/caboose_rets/saved_searches_controller.rb', line 46

def update      
  return if !verify_logged_in
  
  resp = Caboose::StdClass.new({'attributes' => {}})
  search = SavedSearch.find(params[:id])    
  
  save = true
  params.each do |name,value|
    case name
      when 'interval'
        search.interval = value
        resp.attributes['interval'] = { 'text' => "#{value}" }          
  end
end
resp.success = save && search.save  
  render :json => resp
end