Separated routes out into separate namespaces
This commit is contained in:
parent
c8764db47b
commit
4d76c0c072
1
Gemfile
1
Gemfile
@ -1,6 +1,7 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem 'sinatra', '~> 3.0'
|
||||
gem 'sinatra-contrib', '~> 3.0'
|
||||
gem 'puma', '~> 6.0'
|
||||
|
||||
gem 'sequel', '~> 5.63'
|
||||
|
@ -6,6 +6,7 @@ GEM
|
||||
listen (3.7.1)
|
||||
rb-fsevent (~> 0.10, >= 0.10.3)
|
||||
rb-inotify (~> 0.9, >= 0.9.10)
|
||||
multi_json (1.15.0)
|
||||
mustermann (3.0.0)
|
||||
ruby2_keywords (~> 0.0.1)
|
||||
nio4r (2.5.8)
|
||||
@ -26,6 +27,12 @@ GEM
|
||||
rack (~> 2.2, >= 2.2.4)
|
||||
rack-protection (= 3.0.4)
|
||||
tilt (~> 2.0)
|
||||
sinatra-contrib (3.0.4)
|
||||
multi_json
|
||||
mustermann (~> 3.0)
|
||||
rack-protection (= 3.0.4)
|
||||
sinatra (= 3.0.4)
|
||||
tilt (~> 2.0)
|
||||
sqlite3 (1.5.4-x64-mingw-ucrt)
|
||||
sqlite3 (1.5.4-x86_64-linux)
|
||||
tilt (2.0.11)
|
||||
@ -39,6 +46,7 @@ DEPENDENCIES
|
||||
rerun
|
||||
sequel (~> 5.63)
|
||||
sinatra (~> 3.0)
|
||||
sinatra-contrib (~> 3.0)
|
||||
sqlite3 (~> 1.5)
|
||||
|
||||
BUNDLED WITH
|
||||
|
164
lib/routes.rb
164
lib/routes.rb
@ -1,163 +1,5 @@
|
||||
get '/' do
|
||||
items = Item.reverse(:updated_at).limit(10).all()
|
||||
erb :index, :locals => {
|
||||
:title => 'Dashboard',
|
||||
:items => items
|
||||
}
|
||||
end
|
||||
require_relative 'routes/index.rb'
|
||||
|
||||
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
|
||||
require_relative 'routes/item.rb'
|
||||
|
||||
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
|
||||
|
||||
get '/item/:item_id/edit' do
|
||||
item = Item.where(id: params[:item_id]).first()
|
||||
puts "#{item.name}"
|
||||
erb :'item/edit', :locals => {
|
||||
:title => "Editing: #{item.name}",
|
||||
:item => item
|
||||
}
|
||||
end
|
||||
post '/item/:item_id/edit' do
|
||||
item = Item.where(id: params[:item_id]).first()
|
||||
|
||||
item.name = params[:item_name]
|
||||
item.serial_number = params[:item_serial]
|
||||
item.sku_number = params[:item_sku]
|
||||
item.purchased_from = params[:item_purchase_from]
|
||||
item.purchased_at = params[:item_purchase_date]
|
||||
item.manufacturer = params[:item_manufacturer]
|
||||
item.type = params[:item_type]
|
||||
item.save()
|
||||
|
||||
redirect "/item/#{item.id}"
|
||||
end
|
||||
|
||||
get '/item/:item_id/delete' do
|
||||
item = Item.where(id: params[:item_id]).first()
|
||||
item.delete()
|
||||
|
||||
redirect '/item/list'
|
||||
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
|
||||
|
||||
get '/license/:license_id/edit' do
|
||||
license = License.where(id: params[:license_id]).first()
|
||||
puts "#{license.name}"
|
||||
erb :'license/edit', :locals => {
|
||||
:title => "Editing: #{license.name}",
|
||||
:license => license
|
||||
}
|
||||
end
|
||||
post '/license/:license_id/edit' do
|
||||
license = License.where(id: params[:license_id]).first()
|
||||
|
||||
license.name = params[:license_name]
|
||||
license.key = params[:license_key]
|
||||
license.manufacturer = params[:license_manufacturer]
|
||||
license.seats_used = params[:license_seats_used]
|
||||
license.seats_total = params[:license_seats_total]
|
||||
license.purchased_from = params[:license_purchase_from]
|
||||
license.purchased_at = params[:license_purchase_date]
|
||||
license.save()
|
||||
|
||||
redirect "/license/#{license.id}"
|
||||
end
|
||||
|
||||
get '/license/:license_id/delete' do
|
||||
license = License.where(id: params[:license_id]).first()
|
||||
license.delete()
|
||||
|
||||
redirect '/license/list'
|
||||
end
|
||||
|
||||
post '/license/:license_id/comment' do
|
||||
license = License.first(id: params[:license_id])
|
||||
|
||||
comment = LicenseComment.create(body: params[:comment_body])
|
||||
license.add_license_comment(comment)
|
||||
|
||||
redirect "/license/#{license.id}"
|
||||
end
|
||||
require_relative 'routes/license.rb'
|
||||
|
12
lib/routes/index.rb
Normal file
12
lib/routes/index.rb
Normal file
@ -0,0 +1,12 @@
|
||||
namespace '/' do
|
||||
|
||||
get '' do
|
||||
items = Item.reverse(:updated_at).limit(10).all()
|
||||
erb :index, :locals => {
|
||||
:title => 'Dashboard',
|
||||
:items => items
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
|
81
lib/routes/item.rb
Normal file
81
lib/routes/item.rb
Normal file
@ -0,0 +1,81 @@
|
||||
namespace '/item' do
|
||||
|
||||
get '' do
|
||||
redirect '/item/list'
|
||||
end
|
||||
get '/list' do
|
||||
items = Item.reverse(:updated_at).all()
|
||||
erb :'item/list', :locals => {
|
||||
:title => 'List of Items',
|
||||
:items => items
|
||||
}
|
||||
end
|
||||
|
||||
get '/create' do
|
||||
erb :'item/create', :locals => {
|
||||
:title => 'Create New Item'
|
||||
}
|
||||
end
|
||||
post '/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_id' do
|
||||
item = Item.where(id: params[:item_id]).first()
|
||||
puts "#{item.name}"
|
||||
erb :'item/view', :locals => {
|
||||
:title => item.name,
|
||||
:item => item
|
||||
}
|
||||
end
|
||||
|
||||
get '/:item_id/edit' do
|
||||
item = Item.where(id: params[:item_id]).first()
|
||||
puts "#{item.name}"
|
||||
erb :'item/edit', :locals => {
|
||||
:title => "Editing: #{item.name}",
|
||||
:item => item
|
||||
}
|
||||
end
|
||||
post '/:item_id/edit' do
|
||||
item = Item.where(id: params[:item_id]).first()
|
||||
|
||||
item.name = params[:item_name]
|
||||
item.serial_number = params[:item_serial]
|
||||
item.sku_number = params[:item_sku]
|
||||
item.purchased_from = params[:item_purchase_from]
|
||||
item.purchased_at = params[:item_purchase_date]
|
||||
item.manufacturer = params[:item_manufacturer]
|
||||
item.type = params[:item_type]
|
||||
item.save()
|
||||
|
||||
redirect "/item/#{item.id}"
|
||||
end
|
||||
|
||||
get '/:item_id/delete' do
|
||||
item = Item.where(id: params[:item_id]).first()
|
||||
item.delete()
|
||||
|
||||
redirect '/item/list'
|
||||
end
|
||||
|
||||
post '/: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
|
||||
|
||||
end
|
81
lib/routes/license.rb
Normal file
81
lib/routes/license.rb
Normal file
@ -0,0 +1,81 @@
|
||||
namespace '/license' do
|
||||
|
||||
get '' do
|
||||
redirect '/license/list'
|
||||
end
|
||||
get '/list' do
|
||||
licenses = License.reverse(:updated_at).all()
|
||||
erb :'license/list', :locals => {
|
||||
:title => 'List of Licenses',
|
||||
:licenses => licenses
|
||||
}
|
||||
end
|
||||
|
||||
get '/create' do
|
||||
erb :'license/create', :locals => {
|
||||
:title => 'Create New License'
|
||||
}
|
||||
end
|
||||
post '/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_id' do
|
||||
license = License.where(id: params[:license_id]).first()
|
||||
puts "#{license.name}"
|
||||
erb :'license/view', :locals => {
|
||||
:title => license.name,
|
||||
:license => license
|
||||
}
|
||||
end
|
||||
|
||||
get '/:license_id/edit' do
|
||||
license = License.where(id: params[:license_id]).first()
|
||||
puts "#{license.name}"
|
||||
erb :'license/edit', :locals => {
|
||||
:title => "Editing: #{license.name}",
|
||||
:license => license
|
||||
}
|
||||
end
|
||||
post '/:license_id/edit' do
|
||||
license = License.where(id: params[:license_id]).first()
|
||||
|
||||
license.name = params[:license_name]
|
||||
license.key = params[:license_key]
|
||||
license.manufacturer = params[:license_manufacturer]
|
||||
license.seats_used = params[:license_seats_used]
|
||||
license.seats_total = params[:license_seats_total]
|
||||
license.purchased_from = params[:license_purchase_from]
|
||||
license.purchased_at = params[:license_purchase_date]
|
||||
license.save()
|
||||
|
||||
redirect "/license/#{license.id}"
|
||||
end
|
||||
|
||||
get '/:license_id/delete' do
|
||||
license = License.where(id: params[:license_id]).first()
|
||||
license.delete()
|
||||
|
||||
redirect '/license/list'
|
||||
end
|
||||
|
||||
post '/:license_id/comment' do
|
||||
license = License.first(id: params[:license_id])
|
||||
|
||||
comment = LicenseComment.create(body: params[:comment_body])
|
||||
license.add_license_comment(comment)
|
||||
|
||||
redirect "/license/#{license.id}"
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user