Skip to content

Commit

Permalink
API v1 navigation endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
wvengen committed Oct 13, 2018
1 parent 8983b60 commit 9a2cbdf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/controllers/api/v1/navigations_controller.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
namespace :v1 do
resource :user, only: [:show]
resource :config, only: [:show]
resource :navigation, only: [:show]
end
end

Expand Down

0 comments on commit 9a2cbdf

Please sign in to comment.