-
Notifications
You must be signed in to change notification settings - Fork 0
/
easy_retro.rb
91 lines (64 loc) · 1.73 KB
/
easy_retro.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require 'sinatra'
require 'slim'
require 'sinatra/base'
Dir["./lib/**/*.rb"].each { |helper| require helper }
Dir["./models/**/*.rb"].each { |model| require model }
set :root, File.dirname(__FILE__)
class EasyRetroApp < Sinatra::Base
configure :development do
require 'sinatra/reloader'
register Sinatra::Reloader
end
before do
content_type :json
end
get '/' do
content_type :html
slim :board, :locals => { :board_name => "demo" }
end
get '/terms' do
content_type :html
slim :terms
end
get '/:name' do |name|
content_type :html
slim :board, :locals => { :board_name => name}
end
post '/board' do
status 201
redirect "/board/#{params['name']}", 303 if Board.find_by_name(params['name'])
Board.create(:name => params['name'], :post_its => []).to_json
end
get '/board/:name' do |name|
Board.find_by_name(name).to_json
end
post '/board/:name/post_it' do |name|
status 201
board = Board.find_by_name(name)
post_it = board.add_using params[:post_it]
post_it.to_json
end
get '/board/:name/post_it/:id' do |name, id|
status 200
board = Board.find_by_name(name)
post_it = board.find id
return not_found if post_it == nil
post_it.to_json
end
put '/board/:name/post_it/:id' do |name, id|
status 200
board = Board.find_by_name(name)
post_it = board.find id
return not_found if post_it == nil
post_it.update_attributes!(params[:post_it])
post_it.to_json
end
delete '/board/:name/post_it/:id' do |name, id|
status 200
board = Board.find_by_name(name)
post_it = board.find id
return not_found if post_it == nil
board.pull :post_its => {:_id => post_it.id}
post_it.to_json
end
end