Class: Pattana::Api::V1::CitiesController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Pattana::Api::V1::CitiesController
- Defined in:
- app/controllers/pattana/api/v1/cities_controller.rb
Instance Method Summary collapse
Instance Method Details
#cities_in_a_country ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/pattana/api/v1/cities_controller.rb', line 6 def cities_in_a_country proc_code = Proc.new do @country = Country.find_by_id(params[:country_id]) if @country @relation = @country.cities.includes(:region, :country).show_in_api(true).order("cities.name ASC") @relation = @relation.search(params[:q]) if params[:q] @relation = @relation.operational(true) if params[:operational] && ["y","t","yes","true",1].include?(params[:operational].downcase) @cities = @relation.all @data = ActiveModelSerializers::SerializableResource.new(@cities, each_serializer: CityPreviewSerializer) @success = true else @success = false @errors = { heading: I18n.translate("api.cities.country_not_found.heading"), message: I18n.translate("api.cities.country_not_found.message") } end end render_json_response(proc_code) end |
#cities_in_a_region ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/pattana/api/v1/cities_controller.rb', line 27 def cities_in_a_region proc_code = Proc.new do @region = Region.find_by_id(params[:region_id]) if @region @relation = @region.cities.includes(:region, :country).show_in_api(true).order("cities.name ASC") @relation = @relation.search(params[:q]) if params[:q] @relation = @relation.operational(true) if params[:operational] && ["y","t","yes","true",1].include?(params[:operational].downcase) @cities = @relation.all @data = ActiveModelSerializers::SerializableResource.new(@cities, each_serializer: CityPreviewSerializer) @success = true else @success = false @errors = { heading: I18n.translate("api.cities.region_not_found.heading"), message: I18n.translate("api.cities.region_not_found.message") } end end render_json_response(proc_code) end |