Rails.application.routes.draw do

  resources :recipes do
    resources :logs, only: [:new, :create]
  end

  resources :logs, except: [:new, :create]

  resources :ingredients, except: [:show] do
    collection do
      get :usda_food_search

      constraints format: 'json' do
        get :search
        get :prefetch
        get :convert
      end
    end
  end

  match '/ingredients(/:id)/select_ndbn' => 'ingredients#select_ndbn', via: [:post, :patch, :put]

  resource :user, only: [:new, :create, :edit, :update]

  get '/login' => 'users#login', as: :login
  post '/login' => 'users#verify_login'
  get '/logout' => 'users#logout', as: :logout

  get '/about' => 'home#about', as: :about

  scope '/calculator', controller: :calculator, as: :calculator do
    get '/' => :index
    get '/calculate' => :calculate
    get '/ingredient_search' => :ingredient_search
  end

  namespace 'admin' do
    resources :users, except: [:new, :create]
  end

  root 'recipes#index'


end
