Module: Auth::Concerns::Shopping::PlaceControllerConcern

Extended by:
ActiveSupport::Concern
Included in:
Shopping::PlacesController
Defined in:
app/controllers/auth/concerns/shopping/place_controller_concern.rb

Instance Method Summary collapse

Instance Method Details

#createObject

expects the product id, resource_id is the logged in resource, and quantity



29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/auth/concerns/shopping/place_controller_concern.rb', line 29

def create
  ##ensure that the cart item is new
 
  check_for_create(@auth_shopping_place)
  @auth_shopping_place = add_owner_and_signed_in_resource(@auth_shopping_place)
   
  @auth_shopping_place.save

  respond_with @auth_shopping_place
end

#destroyObject

can be removed. responds with 204, and empty response body, if all is ok.



66
67
68
69
70
# File 'app/controllers/auth/concerns/shopping/place_controller_concern.rb', line 66

def destroy
  not_found if @auth_shopping_place.nil?
  @auth_shopping_place.destroy
  respond_with @auth_shopping_place
end

#indexObject

should show those cart items which do not have a parent_id. since these are the pending cart items. all remaining cart items have already been assigned to carts



58
59
60
61
# File 'app/controllers/auth/concerns/shopping/place_controller_concern.rb', line 58

def index
  @auth_shopping_places = @auth_shopping_place_class.find_places({:resource => lookup_resource}).page 1
  respond_with @auth_shopping_places
end

#initialize_varsObject

if an id is provided in the permitted params then tries to find that in the database, and makes a new cart item out of it. if no id is provided then creates a new place from the permitted params, but excluding the id key. if a collection i.e plural resources is present in the permitted_params and its also there in our auth resources, then create a resource class and resource symbol out of it and assign resource as in the comments.



18
19
20
21
22
23
24
25
# File 'app/controllers/auth/concerns/shopping/place_controller_concern.rb', line 18

def initialize_vars
  instantiate_shopping_classes


  @auth_shopping_place_params = permitted_params.fetch(:place,{})
  @auth_shopping_place = params[:id] ? @auth_shopping_place_class.find_self(params[:id],current_signed_in_resource) : @auth_shopping_place_class.new(@auth_shopping_place_params)
  
end

#permitted_paramsObject

this permitted params is overridden in the dummy app, and as a result throws unpermitted parameters for the daughter app parameters, even though they are subsequently permitted, since super is called first.



87
88
89
90
91
92
# File 'app/controllers/auth/concerns/shopping/place_controller_concern.rb', line 87

def permitted_params

  params.permit({place: [:full_address, :unit_number, :building, :street, :pin_code, :city, :country_state, :country, :latitude, :longitude]},:id,:query_string)
  

end

#searchObject



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/controllers/auth/concerns/shopping/place_controller_concern.rb', line 72

def search
  args = {:query_string => params[:query_string]}
  query_clause = Auth::Search::Main.es_six_finalize_search_query_clause(args)
  @search_results = Auth.configuration.place_class.constantize.es.search(query_clause,{:wrapper => :load}).results
  respond_to do |format|
    format.js do 
      render :partial => "search", locals: {search_results: @search_results, suggestions: []}
    end
    format.json do 
      render json: @search_results.to_json
    end
  end
end

#showObject



50
51
52
53
# File 'app/controllers/auth/concerns/shopping/place_controller_concern.rb', line 50

def show
  not_found if @auth_shopping_place.nil?
  respond_with @auth_shopping_place 
end

#updateObject

only permits the quantity to be changed, transaction id is internally assigned and can never be changed by the external world.



41
42
43
44
45
46
47
48
# File 'app/controllers/auth/concerns/shopping/place_controller_concern.rb', line 41

def update
  check_for_update(@auth_shopping_place)
  @auth_shopping_place.assign_attributes(@auth_shopping_place_params)
  @auth_shopping_place = add_owner_and_signed_in_resource(@auth_shopping_place)  
  @auth_shopping_place.save
  puts @auth_shopping_place.errors.full_messages.to_s
  respond_with @auth_shopping_place
end