-
Notifications
You must be signed in to change notification settings - Fork 1
/
balance.py
37 lines (30 loc) · 1.04 KB
/
balance.py
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
from models import *
import webapp2
class User(webapp2.RequestHandler):
# calculate amount needs to pay
def get(self):
uids = self.request.get('uids', [])
#validate data
amount = {}
for uid in uids:
from_balances = Balance.query(from_user=uid,
to_user in uids)
to_balances = Balance.query(to_user=uid,
from_user in uids)
from_amount = reduce(lambda x,y: x.value+y.value, from_balances)
to_amount = reduce(lambda x,y: x.value+y.value, to_balances)
amount[uid] = from_amount - to_amount
# render results
return
# make the payment
def post(self):
uids = self.request.get('uids', [])
#validate data
balances = Balance.query(from_user in uid,
to_user in uid)
@ndb.transactional
def pay():
for b in balances:
b.value = 0
b.put()
pay()