Class: GeoMasterJp::AreaApiController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- GeoMasterJp::AreaApiController
- Defined in:
- app/controllers/geo_master_jp/area_api_controller.rb
Instance Method Summary collapse
Instance Method Details
#cities ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/geo_master_jp/area_api_controller.rb', line 16 def cities if params[:prefecture_code].blank? return render json: { message: 'prefecture_code is required.' }, status: 400 end cities = GeoMasterJp::Prefecture.find_by(code: params[:prefecture_code]).cities cities = GeoMasterJp.config.api.cities_filter.call(cities) if GeoMasterJp.config.api.cities_filter render json: { cities: cities.map{|city| city.as_json(only: [:code, :name, :name_kana, :name_alphabet, :short_name]) }, initials: cities.sort_by(&:name_kana).group_by(&:head_kana).sort_by(&:first).to_h } end |
#prefectures ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/controllers/geo_master_jp/area_api_controller.rb', line 3 def prefectures prefectures = GeoMasterJp::Prefecture.all prefectures = GeoMasterJp.config.api.prefectures_filter.call(prefectures) if GeoMasterJp.config.api.prefectures_filter render json: { prefectures: prefectures.map{|prefecture| prefecture.as_json(only: [:code, :name, :name_kana, :name_alphabet, :short_name]) }, initials: prefectures.sort_by(&:name_kana).group_by(&:head_kana).sort_by(&:first).to_h } end |
#towns ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/geo_master_jp/area_api_controller.rb', line 35 def towns if params[:city_code].blank? return render json: { message: 'city_code is required.' }, status: 400 end towns = GeoMasterJp::City.find_by(code: params[:city_code]).towns towns = GeoMasterJp.config.api.towns_filter.call(towns) if GeoMasterJp.config.api.towns_filter render json: { towns: towns.map{|town| town.as_json(only: [:zip_code, :code, :name, :name_kana, :name_alphabet, :short_name]) }, initials: towns.sort_by(&:name_kana).group_by(&:head_kana).sort_by(&:first).to_h } end |