-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistradeiro.py
56 lines (38 loc) · 1.14 KB
/
registradeiro.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
from bottle import route, run, request
db_cache = []
@route('/api/users', method='GET')
def get_users():
return {'result': db_cache, 'total': len(db_cache)}
@route('/api/users/<user_uid>', method='GET')
def get_user(user_uid):
for item in db_cache:
if item['uid'] == user_uid:
return item
return {'result': {}}
@route('/api/users', method='POST')
def add_user():
data = request.json
db_cache.append(data)
return data
@route('/api/users/<user_uid>', method='PUT')
def edit_user(user_uid):
data = request.json
user = {}
for item in db_cache:
if item['uid'] == user_uid:
user = item
db_cache.remove(item)
if user:
for key, value in data.items():
user[key] = value
db_cache.append(user)
return {'result': user}
@route('/api/users/<user_uid>', method='DELETE')
def delete_user(user_uid):
for item in db_cache:
if item['uid'] == user_uid:
db_cache.remove(item)
return {'result': db_cache, 'total': len(db_cache)}
run(host='localhost', port=8080,
debug=True, reloader=True)