-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmoney.rb
78 lines (54 loc) · 1.35 KB
/
money.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
require 'rubygems'
require 'sinatra'
require 'dm-core'
require 'dm-timestamps'
require 'dm-migrations'
DataMapper::setup(:default, "sqlite://#{Dir.pwd}/money.db")
#Models
class Transaction
include DataMapper::Resource
property :id, Serial
property :source_id, Integer
property :target_id, Integer
property :amount, Decimal, :precision => 10, :scale => 2
property :title, String
property :description, Text
property :is_paid, Boolean
property :created_at, DateTime
property :updated_at, DateTime
belongs_to :source, 'User', :key => true
belongs_to :target, 'User', :key => true
end
class User
include DataMapper::Resource
property :id, Serial
property :name, String
property :email, String
has n, :transactions, :child_key => [ :source_id ]
has n, :transactions, :child_key => [ :target_id ]
end
#Build, update
DataMapper.finalize
DataMapper.auto_upgrade!
#Functions
def getTotal(you, them)
end
def payDebts(date)
end
#Routes
before do
headers "Content-Type" => "text/html; charset=utf-8"
end
get '/' do
'Welcome to money'
end
get '/list' do
@bills = Transaction.all(:source_id => 1)
@users = User.all();
erb :list
end
get '/payDebt/:id' do
bill = Transaction.get(params[:id])
bill.update(:isPaid => 1;
redirect('/list')
end