This repository was archived by the owner on Jun 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinventory_server.py
More file actions
162 lines (116 loc) · 4.26 KB
/
inventory_server.py
File metadata and controls
162 lines (116 loc) · 4.26 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
from flask import Flask, request, jsonify
from flask_restful import abort
from flask_cors import CORS
import db
app = Flask(__name__)
CORS(app)
try:
db.add_user("jesse", "fooey")
except:
pass
@app.route("/api/check_login", methods=["POST"])
def check_login():
content = request.json
password = content.get("password")
assert len(password) > 4
user_id = db.check_login(password)
db.log_event(user_id, password, f"check_login() with password {password}")
if user_id is None:
abort(403, messsage="Not authenticated")
return
return jsonify({"status": "good"})
@app.route("/api/add_user", methods=["POST"])
def add_user():
content = request.json
current_login = content.get("current_login")
name = content.get("name")
password = content.get("password")
assert len(password) > 4
user_id = db.check_login(current_login)
db.log_event(user_id, current_login, f"create user with name {name} and password {password}",
user_id is not None)
if user_id is None:
abort(403, messsage="Not authenticated")
return
db.add_user(name, password)
return jsonify({"status": "good"})
@app.route("/api/get_items", methods=["GET"])
def get_items():
return jsonify(db.get_all_items())
@app.route("/api/add_item", methods=["POST"])
def add_item():
content: dict = request.json
current_login = content.get("current_login")
name = content.get("name")
location = content.get("location")
barcode = content.get("barcode")
user_id = db.check_login(current_login)
db.log_event(user_id, current_login, f"Add Item {name} @ {location} with barcode {barcode}")
if user_id is None:
abort(403, messsage="Not authenticated")
return
db.add_item(name, location, barcode)
return jsonify({"status": "good"})
@app.route("/api/set_barcode", methods=["POST"])
def set_barcode():
content: dict = request.json
current_login = content.get("current_login")
barcode = content.get("barcode")
item_id = content.get("item_id")
user_id = db.check_login(current_login)
db.log_event(user_id, current_login, f"Update barcode for {item_id} with barcode {barcode}")
if user_id is None:
abort(403, messsage="Not authenticated")
return
db.set_barcode(item_id, barcode)
return jsonify({"status": "good"})
@app.route("/api/id_checkout", methods=["POST"])
def id_checkout():
content: dict = request.json
current_login = content.get("current_login")
item_id = content.get("item_id")
user_id = db.check_login(current_login)
db.log_event(user_id, current_login, f"Checkout item {item_id}")
if user_id is None:
abort(403, messsage="Not authenticated")
return
db.use_item(item_id, user_id)
return jsonify({"status": "good"})
@app.route("/api/id_return", methods=["POST"])
def id_return():
content: dict = request.json
current_login = content.get("current_login")
item_id = content.get("item_id")
user_id = db.check_login(current_login)
db.log_event(user_id, current_login, f"Return item {item_id}")
if user_id is None:
abort(403, messsage="Not authenticated")
return
db.return_item(item_id, user_id)
return jsonify({"status": "good"})
@app.route("/api/barcode_checkout", methods=["POST"])
def barcode_checkout():
content: dict = request.json
current_login = content.get("current_login")
barcode = content.get("barcode")
user_id = db.check_login(current_login)
db.log_event(user_id, current_login, f"Checkout item barcode {barcode}")
if user_id is None:
abort(403, messsage="Not authenticated")
return
db.use_item_barcode(barcode, user_id)
return jsonify({"status": "good"})
@app.route("/api/barcode_return", methods=["POST"])
def barcode_return():
content: dict = request.json
current_login = content.get("current_login")
barcode = content.get("barcode")
user_id = db.check_login(current_login)
db.log_event(user_id, current_login, f"Return item barcode {barcode}")
if user_id is None:
abort(403, messsage="Not authenticated")
return
db.return_item_barcode(barcode, user_id)
return jsonify({"status": "good"})
if __name__ == '__main__':
app.run(debug=True)