API for Locations

This commit is contained in:
saurabhbhatia committed 2013-11-19 16:24:15 +08:00
1 parent 6040e63034
commit c545c6f172
7 files changed
+60

No files matched your search

@@ -1,5 +1,6 @@
class Panel::Location::BackEnd::LocationsController < OrbitBackendController
include AdminHelper
open_for_visitor :only => [:get_location_categories, :get_categorywise_locations]
def index
@locations = LocationInfo.all
@@ -89,4 +90,43 @@ class Panel::Location::BackEnd::LocationsController < OrbitBackendController
render :json => JSON.pretty_generate(@data)
end
def get_location_categories
check_mobile_api_openness
location_categories = get_categories_for_index
@data = Array.new
location_categories.each do |category|
I18n.locale = :en
name_en = category.title
I18n.locale = :zh_tw
name_zh_tw = category.title
category_id = category.id.to_s
@data << { name_en: name_en, name_zh_tw: name_zh_tw, category_id: category_id, location_link: "http://#{request.host_with_port}"+"/#{panel_location_back_end_locations_get_categorywise_locations_path}"+"?category_id=#{category_id}"}
end
render :json => JSON.pretty_generate(@data)
end
def get_categorywise_locations
check_mobile_api_openness
location_infos = LocationInfo.where(:category_id => params[:category_id])
@data = Array.new
location_infos.each do |location|
picurl = location.file.blank? ? '' : "http://#{request.host_with_port + location.file.url}"
thumburl = location.file.blank? ? '' : "http://#{request.host_with_port + location.file.thumb.url}"
@data << { id: location.id.to_s,
name: location.name,
pic_url: picurl,
thumb_url: thumburl,
longitude: location.longitude,
latitude: location.latitude,
description: location.description }
end
render :json => JSON.pretty_generate(@data)
end
end
+3
View File
@@ -3,6 +3,9 @@ Rails.application.routes.draw do
namespace :location do
namespace :back_end do
match 'location_categories/list' => "location_categories#list"
match "locations/get_locations" => "locations#get_locations"
match "locations/get_categorywise_locations" => "locations#get_categorywise_locations"
match "locations/get_location_categories" => "locations#get_location_categories"
resources :location_categories
match "locations/get_locations" => "locations#get_locations"
match "locations/get_categories" => "locations#get_categories"