Class: Cats::Core::LocationsController

Inherits:
ApplicationController show all
Includes:
Common
Defined in:
app/controllers/cats/core/locations_controller.rb

Instance Method Summary collapse

Methods included from Common

#create, #show, #update

Methods inherited from ApplicationController

#authenticate, #current_user, #skip_bullet

Instance Method Details

#childrenObject



12
13
14
15
# File 'app/controllers/cats/core/locations_controller.rb', line 12

def children
  parent = Location.find(params[:id])
  render json: {success: true, data: serialize(parent.children)}
end

#create_fdpObject



34
35
36
37
38
39
# File 'app/controllers/cats/core/locations_controller.rb', line 34

def create_fdp
  service = LocationService.new
  p = fdp_params
  fdp = service.create_fdp(p[:code], p[:name], p[:parent_id], p[:description])
  render json: {success: true, data: serialize(fdp)}
end

#filterObject



17
18
19
20
# File 'app/controllers/cats/core/locations_controller.rb', line 17

def filter
  query = Location.ransack(params[:q])
  render json: {success: true, data: serialize(query.result)}
end

#filter_location_by_regionObject



22
23
24
25
26
# File 'app/controllers/cats/core/locations_controller.rb', line 22

def filter_location_by_region
  descendants = Location.find(params[:id]).descendants
  query = descendants.ransack(params[:q])
  render json: {success: true, data: serialize(query.result)}
end

#indexObject



6
7
8
9
10
# File 'app/controllers/cats/core/locations_controller.rb', line 6

def index
  super do
    Location.where(location_type: params[:location_type])
  end
end

#woredasObject



28
29
30
31
32
# File 'app/controllers/cats/core/locations_controller.rb', line 28

def woredas
  region = Location.find(params[:id])
  woredas = Location.where(id: region.descendant_ids, location_type: Location::WOREDA)
  render json: {success: true, data: serialize(woredas)}
end