get '/' do items = Item.reverse(:updated_at).limit(10).all() erb :index, :locals => { :title => 'Dashboard', :items => items } end get '/item' do redirect '/item/list' end get '/item/list' do items = Item.reverse(:updated_at).all() erb :'item/list', :locals => { :title => 'List of Items', :items => items } end get '/item/create' do erb :'item/create', :locals => { :title => 'Create New Item' } end post '/item/create' do item = Item.create( name: params[:item_name], serial_number: params[:item_serial], sku_number: params[:item_sku], purchased_from: params[:item_purchase_from], purchased_at: params[:item_purchase_date], manufacturer: params[:item_manufacturer], type: params[:item_type] ) redirect "/item/#{item.id}" end get '/item/:item_id' do item = Item.where(id: params[:item_id]).first puts "#{item.name}" erb :'item/view', :locals => { :title => item.name, :item => item } end post '/item/:item_id/comment' do item = Item.first(id: params[:item_id]) comment = ItemComment.create(body: params[:comment_body]) item.add_item_comment(comment) redirect "/item/#{item.id}" end get '/license' do redirect '/license/list' end get '/license/list' do licenses = License.reverse(:updated_at).all() erb :'license/list', :locals => { :title => 'List of Licenses', :licenses => licenses } end get '/license/create' do erb :'license/create', :locals => { :title => 'Create New License' } end post '/license/create' do license = License.create( name: params[:license_name], key: params[:license_key], manufacturer: params[:license_manufacturer], seats_used: params[:license_seats_used], seats_total: params[:license_seats_total], purchased_from: params[:license_purchase_from], purchased_at: params[:license_purchase_date] ) redirect "/license/#{license.id}" end get '/license/:license_id' do license = License.where(id: params[:license_id]).first() puts "#{license.name}" erb :'license/view', :locals => { :title => license.name, :license => license } end