Module: Auth::Concerns::Shopping::PersonalityControllerConcern

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

Instance Method Summary collapse

Instance Method Details

#createObject

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



22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/auth/concerns/shopping/personality_controller_concern.rb', line 22

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

  respond_with @auth_shopping_personality
end

#destroyObject

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



59
60
61
62
63
# File 'app/controllers/auth/concerns/shopping/personality_controller_concern.rb', line 59

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

#indexObject

will have to have this lookup resource part here. what if we want to create items for the user



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

def index
  @auth_shopping_personalities = @auth_shopping_personality_class.find_personalities({:resource => lookup_resource}).page 1
  respond_with @auth_shopping_personalities
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 personality 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.



12
13
14
15
16
17
18
# File 'app/controllers/auth/concerns/shopping/personality_controller_concern.rb', line 12

def initialize_vars
  instantiate_shopping_classes

  @auth_shopping_personality_params = permitted_params.fetch(:personality,{})
  @auth_shopping_personality = params[:id] ? @auth_shopping_personality_class.find_self(params[:id],current_signed_in_resource) : @auth_shopping_personality_class.new(@auth_shopping_personality_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.



82
83
84
85
86
# File 'app/controllers/auth/concerns/shopping/personality_controller_concern.rb', line 82

def permitted_params

  params.permit({personality: [:date_of_birth, :fullname, :sex, :referred_by, :referrer_contact_number]},:id, :query_string)
  
end

#searchObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/auth/concerns/shopping/personality_controller_concern.rb', line 65

def search
  args = {:query_string => params[:query_string]}
  query_clause = Auth::Search::Main.es_six_finalize_search_query_clause(args)
  @search_results = Auth.configuration.personality_class.constantize.es.search(query_clause,{:wrapper => :load}).results
  respond_to do |format|
    ## with js.
    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



43
44
45
46
# File 'app/controllers/auth/concerns/shopping/personality_controller_concern.rb', line 43

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

#updateObject

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



34
35
36
37
38
39
40
41
# File 'app/controllers/auth/concerns/shopping/personality_controller_concern.rb', line 34

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