Module: Api::Controllers::Base
  
  
  
  
  
  
  
      - Extended by:
 
      - ActiveSupport::Concern
 
  
  
  
  
  
  
  
    - Included in:
 
    - V1::ApplicationController
 
  
  
  
  
    - Defined in:
 
    - app/controllers/concerns/api/controllers/base.rb
 
  
  
 
Defined Under Namespace
  
    
  
    
      Classes: NotAuthenticatedError
    
  
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
    Instance Method Details
    
      
  
  
    
      
100
101
102
103
104 
     | 
    
      # File 'app/controllers/concerns/api/controllers/base.rb', line 100
def 
  collection = instance_variable_get collection_variable
  @pagy, collection = pagy_cursor collection, after: params[:after], order: {id: :asc}
  instance_variable_set collection_variable, collection
end
     | 
  
 
    
      
  
  
    #collection_variable  ⇒ Object 
  
  
  
  
    
      
96
97
98 
     | 
    
      # File 'app/controllers/concerns/api/controllers/base.rb', line 96
def collection_variable
  @collection_variable ||= "@#{self.class.name.split("::").last.gsub("Controller", "").underscore}"
end
     | 
  
 
    
      
  
  
    #current_membership  ⇒ Object 
  
  
  
  
    
      
92
93
94 
     | 
    
      # File 'app/controllers/concerns/api/controllers/base.rb', line 92
def current_membership
  current_user.memberships.where(team: current_team).first
end 
     | 
  
 
    
      
  
  
    #current_team  ⇒ Object 
  
  
  
  
    
      
87
88
89
90 
     | 
    
      # File 'app/controllers/concerns/api/controllers/base.rb', line 87
def current_team
    current_user&.teams&.first
end
     | 
  
 
    
      
  
  
    #current_user  ⇒ Object 
  
  
  
  
    
      
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 
     | 
    
      # File 'app/controllers/concerns/api/controllers/base.rb', line 67
def current_user
  @current_user ||= if doorkeeper_token
    User.find_by(id: doorkeeper_token[:resource_owner_id])
  else
    warden.authenticate(scope: :user)
  end
    if doorkeeper_token
    begin
      doorkeeper_token.update(last_used_at: Time.zone.now)
    rescue ActiveRecord::StatementInvalid => _
    end
  end
  raise NotAuthenticatedError unless @current_user
  @current_user
end
     | 
  
 
    
      
  
  
    #permitted_arrays  ⇒ Object 
  
  
  
  
    
      
60
61
62 
     | 
    
      # File 'app/controllers/concerns/api/controllers/base.rb', line 60
def permitted_arrays
  {}
end
     | 
  
 
    
      
  
  
    #permitted_fields  ⇒ Object 
  
  
  
  
    
      
56
57
58 
     | 
    
      # File 'app/controllers/concerns/api/controllers/base.rb', line 56
def permitted_fields
  []
end 
     | 
  
 
    
      
  
  
    #process_params(strong_params)  ⇒ Object 
  
  
  
  
    
      
64
65 
     | 
    
      # File 'app/controllers/concerns/api/controllers/base.rb', line 64
def process_params(strong_params)
end 
     | 
  
 
    
      
  
  
    
      
106
107
108 
     | 
    
      # File 'app/controllers/concerns/api/controllers/base.rb', line 106
def set_default_response_format
  request.format = :json
end 
     |