Added channel and video models, views, and routes
This commit is contained in:
@ -18,4 +18,8 @@ helpers do
|
||||
return dt.strftime('%Y-%m-%dT%H:%M:%S')
|
||||
end
|
||||
|
||||
def serialize(num)
|
||||
return num
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -2,4 +2,8 @@ class Channel < Sequel::Model
|
||||
|
||||
one_to_many :videos
|
||||
|
||||
def openProjects()
|
||||
return 0
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,5 +1,5 @@
|
||||
class Video < Sequel::Model
|
||||
|
||||
many_to_one :channels
|
||||
many_to_one :channel
|
||||
|
||||
end
|
||||
|
@ -1 +1,5 @@
|
||||
require_relative 'routes/index.rb'
|
||||
|
||||
require_relative 'routes/channel.rb'
|
||||
|
||||
require_relative 'routes/video.rb'
|
||||
|
37
lib/routes/channel.rb
Normal file
37
lib/routes/channel.rb
Normal file
@ -0,0 +1,37 @@
|
||||
namespace '/channel' do
|
||||
|
||||
get '' do
|
||||
redirect '/channel/list'
|
||||
end
|
||||
get '/list' do
|
||||
channels = Channel.reverse(:updated_at).all()
|
||||
erb :'channel/list', :locals => {
|
||||
:title => 'List of channels',
|
||||
:channels => channels
|
||||
}
|
||||
end
|
||||
|
||||
get '/create' do
|
||||
erb :'channel/create', :locals => {
|
||||
:title => 'Create new channel'
|
||||
}
|
||||
end
|
||||
post '/create' do
|
||||
channel = Channel.create(
|
||||
name: params[:channel_name],
|
||||
description: params[:channel_description]
|
||||
)
|
||||
|
||||
redirect "/channel/#{channel.id}"
|
||||
end
|
||||
|
||||
get '/:channel_id' do
|
||||
channel = Channel.where(id: params[:channel_id]).first()
|
||||
puts "#{channel.name}"
|
||||
erb :'channel/view', :locals => {
|
||||
:title => channel.name,
|
||||
:channel => channel
|
||||
}
|
||||
end
|
||||
|
||||
end
|
41
lib/routes/video.rb
Normal file
41
lib/routes/video.rb
Normal file
@ -0,0 +1,41 @@
|
||||
namespace '/video' do
|
||||
|
||||
get '' do
|
||||
redirect '/video/list'
|
||||
end
|
||||
get '/list' do
|
||||
videos = Video.reverse(:updated_at).all()
|
||||
erb :'video/list', :locals => {
|
||||
:title => 'List of videos',
|
||||
:videos => videos
|
||||
}
|
||||
end
|
||||
|
||||
get '/create' do
|
||||
channels = Channel.all()
|
||||
erb :'video/create', :locals => {
|
||||
:title => 'Create new video',
|
||||
:channels => channels
|
||||
}
|
||||
end
|
||||
post '/create' do
|
||||
video = Video.create(
|
||||
serial: params[:video_serial],
|
||||
name: params[:video_name],
|
||||
channel_id: params[:video_channel],
|
||||
description: params[:video_description]
|
||||
)
|
||||
|
||||
redirect "/video/#{video.id}"
|
||||
end
|
||||
|
||||
get '/:video_id' do
|
||||
video = Video.where(id: params[:video_id]).first()
|
||||
puts "#{video.name}"
|
||||
erb :'video/view', :locals => {
|
||||
:title => video.name,
|
||||
:video => video
|
||||
}
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user