-
Notifications
You must be signed in to change notification settings - Fork 0
/
qrriate.rb
67 lines (55 loc) · 1.45 KB
/
qrriate.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
require 'sinatra/base'
require 'json'
require_relative 'models/model.rb'
class Qrriate < Sinatra::Base
configure do
Mongoid.configure do |config|
config.sessions = {
:default => {
:hosts => ["localhost:27017"], :database => "c9"
}
}
end
end
get '/' do
"Hola Arriate!"
end
get '/api/getPoints' do
response.headers['Access-Control-Allow-Origin'] = '*'
if params.empty?
tarjetas={:tarjetas => Tarjeta.all}
tarjetas.to_json
elsif params.has_key?('t')
tarjetas={:tarjetas => Tarjeta.where(tipo: params[:t])}
tarjetas.to_json
elsif params.has_key?('id')
begin
tarjeta={:tarjetas => Tarjeta.find(params[:id])}
tarjeta.to_json
rescue
e = {:error => "Codigo no encontrado"}
e.to_json
end
else
e = {:error => "Invalid query"}
e.to_json
end
end
post '/api/addPoint' do
Tarjeta.create(params)
end
get '/api/count' do
Tarjeta.count.to_s
end
get '/admin' do
@tarjetas = Tarjeta.all
haml :index
end
get '/admin/new' do
haml :new
end
post '/admin/new' do
Tarjeta.create(params)
redirect '/admin'
end
end