You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
732 B
41 lines
732 B
require 'sinatra'
|
|
require 'data_mapper'
|
|
require 'haml'
|
|
|
|
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/development.db")
|
|
|
|
class Task
|
|
include DataMapper::Resource
|
|
property :id, Serial
|
|
property :name, String, required: true
|
|
property :completed_at, DateTime
|
|
end
|
|
|
|
DataMapper.finalize
|
|
|
|
get '/' do
|
|
@tasks = Task.all
|
|
haml :index
|
|
end
|
|
|
|
post '/' do
|
|
Task.create params[:task]
|
|
redirect '/'
|
|
end
|
|
|
|
delete '/task/:id' do
|
|
Task.get(params[:id]).destroy
|
|
redirect '/'
|
|
end
|
|
|
|
put '/task/:id' do
|
|
task = Task.get params[:id]
|
|
task.completed_at = task.completed_at.nil? ? Time.now : nil
|
|
task.save
|
|
redirect '/'
|
|
end
|
|
|
|
get '/:task' do
|
|
@task = params[:task].split('-').join(' ').capitalize
|
|
# haml :task
|
|
end
|