-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory.py
43 lines (34 loc) · 1.19 KB
/
history.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
from flask import request, Response, jsonify, make_response
from flask_restx import Resource, Api, Namespace
from sql import SQL, SQLRequest
from util import Util
HISTORY = Namespace("products/history")
@HISTORY.route("")
class History(Resource):
def get(self):
connection = SQL()
error_msg = {}
data = SQLRequest()
try:
name = request.args.get("name")
cvs = request.args.get("cvs")
if name is None:
error_msg["message"] = "name is empty"
else:
data.add("history_name", name)
if cvs is None:
error_msg["message"] = "cvs is empty"
else:
data.add("cvs", cvs)
if len(error_msg) == 0:
connection.check_connection()
res = connection.processDB(data,True)
code = 200
if len(res)==0:
code = 400
return make_response(jsonify(Util.make_response_json(res)),code)
else:
return make_response(jsonify(error_msg), 400)
except Exception as e:
print(f"error {e}")
raise e