API v1 navigation endpoint
This commit is contained in:
parent
9c5a5d9492
commit
554be093b9
2 changed files with 25 additions and 0 deletions
24
app/controllers/api/v1/navigations_controller.rb
Normal file
24
app/controllers/api/v1/navigations_controller.rb
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
class Api::V1::NavigationsController < Api::V1::BaseController
|
||||||
|
|
||||||
|
def show
|
||||||
|
# we don't use active_model_serializers here, because source is a Hash
|
||||||
|
render json: { navigation: transform(navigation) }
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def navigation
|
||||||
|
render_navigation(renderer: :json, as_hash: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def transform(items)
|
||||||
|
items.map do |item|
|
||||||
|
r = {}
|
||||||
|
r[:name] = item[:name]
|
||||||
|
r[:url] = request.base_url + item[:url] if item[:url] != '#'
|
||||||
|
r[:items] = transform(item[:items]) if item[:items]
|
||||||
|
r
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -247,6 +247,7 @@ Foodsoft::Application.routes.draw do
|
||||||
namespace :v1 do
|
namespace :v1 do
|
||||||
resource :user, only: [:show]
|
resource :user, only: [:show]
|
||||||
resource :config, only: [:show]
|
resource :config, only: [:show]
|
||||||
|
resource :navigation, only: [:show]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue